Php 使用android从mysql检索数据
我遇到了一个问题,例如:我们有2个用户,所以用户a将数据插入数据库,可以毫无问题地检索数据。用户B将数据插入数据库,当用户B想要检索数据时,用户B将获取用户A而不是用户B的数据 是什么导致了这个问题 下面是我从mysql数据库获取数据的php代码:Php 使用android从mysql检索数据,php,android,mysql,Php,Android,Mysql,我遇到了一个问题,例如:我们有2个用户,所以用户a将数据插入数据库,可以毫无问题地检索数据。用户B将数据插入数据库,当用户B想要检索数据时,用户B将获取用户A而不是用户B的数据 是什么导致了这个问题 下面是我从mysql数据库获取数据的php代码: <?php // array for JSON response $response = array(); // include db connect class require_once __DIR__ . '/db_connect.ph
<?php
// array for JSON response
$response = array();
// include db connect class
require_once __DIR__ . '/db_connect.php';
// connecting to db
$db = new DB_CONNECT();
// check for post data
if (isset($_GET["subject_id"])) {
$subject_id = $_GET['subject_id'];
// get a product from products table
$result = mysql_query("SELECT * FROM subject_offered WHERE subject_id = $subject_id");
if (!empty($result)) {
// check for empty result
if (mysql_num_rows($result) > 0) {
$result = mysql_fetch_array($result);
$product = array();
$product["subject_id"] = $result["subject_id"];
$product["lecturer_name"] = $result["lecturer_name"];
$product["time_offered"] = $result["time_offered"];
$product["subject_details"] = $result["subject_details"];
//$product["updated_at"] = $result["updated_at"];
// 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 subject found";
// echo no users JSON
echo json_encode($response);
}
} else {
// no product found
$response["success"] = 0;
$response["message"] = "No subject 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);
}
?>
应该是
// get a product from products table
$result = mysql_query("SELECT * FROM subject_offered WHERE subject_id = '$subject_id' ");
//some times when you miss '' this single commas then it also create a problem
谢谢你的回复,我照你说的做了,但是不起作用!我仍然遇到同样的问题。好吧,如果问题如此复杂,那么请使用分步方法来成功执行,因为修改和测试代码的每个部分太重要了,希望它能给你一些线索。。。
// get a product from products table
$result = mysql_query("SELECT * FROM subject_offered WHERE subject_id = '$subject_id' ");
//some times when you miss '' this single commas then it also create a problem