Last active
August 29, 2015 14:19
-
-
Save ziedrebhi/96315160e0dcb4c687ef to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// array for JSON response | |
$response = array(); | |
// include db connect class | |
require_once __DIR__ . '/db_connect.php'; | |
// connecting to db | |
$con = new DB_CONNECT(); | |
$con->connect(); | |
// check for post data | |
if (isset($_GET["id"])) { | |
$id = $_GET['id']; | |
// get products from products table | |
$result = mysqli_query($con->myconn, "SELECT * FROM products WHERE id_cat = $id"); | |
if (!empty($result)) { | |
// check for empty result | |
if (mysqli_num_rows($result) > 0) { | |
$result = mysqli_fetch_array($result); | |
$product = array(); | |
$product["id"] = $result["id"]; | |
$product["name_prod"] = $result["name_prod"]; | |
$product["price_prod"] = $result["price_prod"]; | |
$product["desc_prod"] = $result["desc_prod"]; | |
$product["image_prod"] = $result["image_prod"]; | |
$product["id_cat"] = $result["id_cat"]; | |
// success | |
$response["success"] = 1; | |
// user node | |
$response["products"] = array(); | |
array_push($response["products"], $product); | |
// echoing JSON response | |
echo json_encode($response); | |
} else { | |
// no product found | |
$response["success"] = 1; | |
$response["message"] = "No product found"; | |
// echo no users JSON | |
echo json_encode($response); | |
} | |
} else { | |
// no product found | |
$response["success"] = 0; | |
$response["message"] = "No product found"; | |
// echo no users JSON | |
echo json_encode($response); | |
} | |
} else { | |
// required field is missing | |
$response["success"] = 0; | |
$response["message"] = "Required field(s) is missing"; | |
// echoing JSON response | |
echo json_encode($response); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment