尝试从 Android 应用程序中的 MySQL 数据库获取数据时遇到问题
输出是:
06-29 11:40:42.123: E/JSON(1426): {"tag":"getroute","success":1,"error":0,"products":[]}
我认为我面临的问题出在我的 PHP 文件中(这是标签的代码):
if( . . . )
{
. . .
}
else if ($tag == 'getroute')
{
$endloc = $_POST['end'];
$op = $db->getRoutes($endloc);
if ($op)
{
$response["products"] = array();
while($data= mysql_fetch_assoc($op))
{
$product = array();
$product ["uname"] = $data["uname"];
$product ["start"] = $data["start"];
$product ["end"] = $data["end"];
$product ["meet1"] = $data["meet1"];
$product ["meet1time"] = $data["meet1time"];
$product ["meet2"] = $data["meet2"];
$product ["meet2time"] = $data["meet2time"];
$product ["meet3"] = $data["meet3"];
$product ["meet3time"] = $data["meet3time"];
$product ["ismoke"] = $data["ismoke"];
$product ["iwomen"] = $data["iwomen"];
$product ["ctime"] = $data["ctime"];
$product ["seats"] = $data["seats"];
// push single product into final response array
array_push($response["products"], $product);
}
$response["success"] = 1;
echo json_encode($response);
// user stored successfully
}
else
{
// user failed to store
$response["error"] = 1;
$response["error_msg"] = "Error occured in Making Route";
echo json_encode($response);
}
}
我不知道问题出在哪里。我在互联网上搜索并找到了一些教程,但他们总是给我这个错误。
函数 getroute :
public function getRoutes($endlocation)
{
$result = mysql_query("SELECT * FROM routes WHERE end = '$endlocation'");
return $result;
}