-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata.php
48 lines (43 loc) · 1.12 KB
/
data.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
<?php
#Include the connect.php file
# FileName="connect.php"
$hostname = "localhost";
$database = "employees";
$username = "root";
$password = "root";
// Connect to the database
$mysqli = new mysqli($hostname, $username, $password, $database);
/* check connection */
if (mysqli_connect_errno())
{
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
// get data and store in a json array
$from = 0;
$to = 30;
$query = "SELECT CompanyName, ContactName, ContactTitle, Address, City FROM employees ";
$query=$query."WHERE CompanyName='".$_GET['CompanyName']. "'";
$query=$query." LIMIT ?,?";
$result = $mysqli->prepare($query);
$result->bind_param('ii', $from, $to);
$result->execute();
/* bind result variables */
$result->bind_result($CompanyName, $ContactName, $ContactTitle, $Address, $City);
/* fetch values */
while ($result->fetch())
{
$employees[] = array(
'CompanyName' => $CompanyName,
'ContactName' => $ContactName,
'ContactTitle' => $ContactTitle,
'Address' => $Address,
'City' => $City
);
}
echo json_encode($employees);
/* close statement */
$result->close();
/* close connection */
$mysqli->close();
?>