-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconnection.php
executable file
·100 lines (84 loc) · 3.71 KB
/
connection.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
$servername = "localhost";
$username = "root";
$password = "password";
$dbname = 'nppDemo_db';
// Create connection
$conn = new mysqli($servername, $username, $password,$dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$mapDetail = $_REQUEST['map-detail'];
$stateId = $mapDetail['stateId'];
$discomId = $mapDetail['discomId'];
$townName = $mapDetail['townName'];
$levelLocation = $mapDetail['levelLocation'];
if($_REQUEST['section'] == 'state'){
$sql = "SELECT
state_discom_mapping_tbl.state_id,
state_discom_mapping_tbl.`discom_id`,
state_discom_mapping_tbl.`town_name`,
discom_tbl.`location` ,
state_discom_mapping_tbl.`discom_name` as 'title'
FROM
`state_discom_mapping_tbl`
LEFT JOIN `discom_tbl`
ON `discom_tbl`.`discom_id` = `state_discom_mapping_tbl`.`discom_id`
WHERE state_discom_mapping_tbl.`state_id` = $stateId
GROUP BY state_discom_mapping_tbl.`town_name` ";
}else if(($_REQUEST['section'] == 'all-india')){
$sql = "SELECT
state_discom_mapping_tbl.state_id,
state_discom_mapping_tbl.`discom_id`,
state_discom_mapping_tbl.`town_name`,
state_tbl.`location`,
state_tbl.`state_name` as 'title'
FROM
`state_tbl`
LEFT JOIN `state_discom_mapping_tbl`
ON `state_discom_mapping_tbl`.`state_id` = `state_tbl`.`state_id`
GROUP BY state_discom_mapping_tbl.`discom_id` ";
}else if(($_REQUEST['section'] == 'discom')){
$sql = "SELECT
state_discom_mapping_tbl.state_id,
state_discom_mapping_tbl.`discom_id`,
state_discom_mapping_tbl.`town_name` as 'title',
town_tbl.`location`,
state_discom_mapping_tbl.description
FROM
`state_discom_mapping_tbl`
LEFT JOIN `discom_tbl`
ON `discom_tbl`.`discom_id` = `state_discom_mapping_tbl`.`discom_id`
LEFT JOIN `town_tbl`
ON town_tbl.`town_name` = state_discom_mapping_tbl.`town_name`
WHERE state_discom_mapping_tbl.`discom_id` = $discomId";
}
$result = $conn->query($sql);
$datatoReturn = array();
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$datatoReturn[] = $row;
}
} else {
echo "0 results";
}
foreach($datatoReturn as &$value){
$value['description'] = trim(preg_replace( "/\r|\n/", "<br/>", $value['description']));
$value['description'] = explode('<br/>',$value['description']);
$previous = $value['description'][5];
$townss = explode(':',$value['description'][5]);
$townss[1] = (trim(preg_replace('/[^A-Za-z0-9\-]/', '', $townss[1])) ? trim(preg_replace('/[^A-Za-z0-9\-]/', '', $townss[1])): ' NO ' );
if($townss[1] == 'YES') {
$value['description'][5] = $previous;
$value['description'] = "Description<br/>" . $value['description'][1] . "<br/>" . $value['description'][2]
. "<br/>" . $value['description'][3] . "<br/>" . $value['description'][4] . "<br/>" . $value['description'][5] . "<br/>" . $value['description'][6] . "<br/>" . $value['description'][7];
}else{
$value['description'] = "Description<br/>" . $value['description'][1] . "<br/>" . $value['description'][2]
. "<br/>" . $value['description'][3] . "<br/>" . $value['description'][4] . "<br/> Go_Live_In:".$townss[1]." <br/>" . $value['description'][6] . "<br/>" . $value['description'][7];
}
}
echo json_encode($datatoReturn);
$conn->close();
?>