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
| <?php
$un=$_GET['username'];
$ID=$_GET['id'];
/*
* Following code will list all the products
*/
// array for JSON response
$response = array();
$user = 'root';
$pswd = '';
$db = 'crm';
$conn = mysql_connect('localhost', $user, $pswd);
mysql_select_db($db, $conn);
// get all products from product table
$result = mysql_query("select distinct PRODUCTTYPEID from product p , producttype pt where p.PRODUCTTYPEID=pt.ID ") or die(mysql_error());
// check for empty result
if( resultset) {
// looping through all results
// products node
"select PRODUCTNAME from product where PRODUCTTYPEID='$ID'";}
else
{"select PRODUCTTYPENAME from producttype where ARBORESCENCEID='$ID'"}
while ($row = mysql_fetch_array($result)) {
// temp user array
$product = array();
$product["ID"] = $row["ID"];
$product["PRODUCTTYPENAME"] = utf8_encode($row["PRODUCTTYPENAME"]);
$product["PRODUCTNAME"] = utf8_encode($row["PRODUCTNAME"]);
// push single product into final response array
array_push($response["product"], $product);
}
// success
$response["success"] = 1;
// echoing JSON response
echo json_encode($response);
} else {
// no products found
$response["success"] = 0;
$response["message"] = "No products found";
// echo no users JSON
echo json_encode($response);
}
?> |
Partager