当我编写 select 语句时,它总是返回数据库中最后插入的行。有什么问题,我该如何解决?
重要提示:我的一个朋友使用了相同的代码,并且对她很有效!
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);