运行服务器端的 PHP 脚本来处理来自 Java 应用程序的查询。该表有 450 个应该返回的结果,但由于某种原因,它进入了 no business found 语句。
用于测试我使用以下 vals 从 android 应用程序发送有关 HTTPGet 的信息
varQuery2 是一个字符串并且 = 状态 varQuery1 是一个字符串并且 = MS
<?php
$result = mysql_query("SELECT * FROM businessdata WHERE '"
. mysql_real_escape_string($_REQUEST['varQuery2'])."' = '"
. mysql_real_escape_string($_REQUEST['varQuery1'])."'") or die(mysql_error());
// check for empty result
if (mysql_num_rows($result) > 0) {
// looping through all results
// businesses node
$response["businesses"] = array();
while ($row = mysql_fetch_array($result)) {
// temp user array
$business = array();
$business["bid"] = $row["idbusinessData"];
$business["name"] = $row["name"];
$business["owner"] = $row["owner"];
$business["phone_main"] = $row["phone_main"];
array_push($response["businesses"], $business);
}
// success
$response["success"] = 1;
// echoing JSON response
echo json_encode($response);
} else {
// no businesses found
$response["success"] = 0;
$response["message"] = "No businesses found";
// echo no users JSON
echo json_encode($response);
}
?>
为什么这会失败以及如何解决它的任何想法?另请注意,整个脚本在选择中使用 static state = 'MS' ......即使我从浏览器窗口调用它:
http://address/scriptName.php?varQuery2=state+varQuery1=MS
我仍然得到相同的未找到业务响应..
根据评论,下面是这里使用的表格..
CREATE TABLE `test`.`businessData` (
`idbusinessData` INT NOT NULL AUTO_INCREMENT ,
`name` CHAR(255) NULL ,
`owner` CHAR(255) NULL ,
`phone_main` CHAR(10) NULL ,
PRIMARY KEY (`idbusinessData`) );
只是一点点更新,看看我是否走在正确的轨道上:
switch ($_GET){
case "state":
$result = mysql_query("SELECT * FROM businessdata WHERE state = '" . mysql_real_escape_string($_REQUEST['varQuery1'])."'") or die(mysql_error());
case "zip";
// zipcode results
case "nothing";
// default results
}