When I wrote the select statement it always return the last inserted row in the database. What is the problem, and how can I fix it?
Important NOTE: A friend of mine took the same code and it worked for her properly!
if (isset($_GET["name"])) {
$pid = $_GET['name'];
// get a product from products table
//)or die(mysql_error()
$result = mysql_query("SELECT * FROM food WHERE name = $pid");
//mysql_query($result,$con);
if (!empty($result)) {
// check for empty result
if (mysql_num_rows($result) > 0) {
$result = mysql_fetch_array($result);
$product = array();
$product["name"] = $result["name"];
$product["unit"] = $result["unit"];
$product["calory"] = $result["calory"];
$product["carbohydrate"] = $result["carbohydrate"];
$product["category"] = $result["category"];
// success
$response["success"] = 1;
// user node
$response["product"] = array();
array_push($response["product"], $product);
// echoing JSON response
echo json_encode($response);
} else {
// no product found
$response["success"] = 0;
$response["message"] = "No item 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);
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…