Page 38 - 3-2
P. 38
//$db = new DB_CONNECT();
// get all products from products table
$result = mysqli_query($con,"SELECT *FROM mdp_table4") or die(mysqli_error());
// check for empty result
if (mysqli_num_rows($result) > 0) {
// looping through all results
// products node
$response["products"] = array();
while ($row = mysqli_fetch_array($result)) {
// temp user array
$product = array();
$product["code"] = $row["code"];
$product["name"] = $row["name"];
$product["num"] = $row["num"];
$product["price"] = $row["price"];
// push single product into final response array
array_push($response["products"], $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);
}
mysqli_close($con);
?>
----------------*delete_product_menu.php*-------------
<?php
/*
* Following code will delete a product from table
* A product is identified by product id (pid)
*/
// array for JSON response
- 38 -