您的网址上缺少一个&
,应该是:
http://www.celeritas-solutions.com/pah_brd_v1/productivo/getSubCategory.php?OrganizationCode=celeritas&CategoryId=3
仔细观察,你有:
OrganizationCode=celeritasCategoryId=3
它应该是:
OrganizationCode=celeritas&CategoryId=3
这会导致$CategoryId
未设置(或换句话说为空),这会使您的查询失败并且没有结果。
您应该使用isset
确保您的变量已设置:
$OrganizationCode = $_GET['OrganizationCode'];
if (!isset($OrganizationCode))
die("There is no organization code...");
$CategoryId = $_GET['CategoryId'];
if (!isset($CategoryId))
die("There is no category id...");
以及使用mysql-real-escape-string
和正确使用错误处理程序对其进行清理以防止注入,以了解查询是否失败mysql_error
:
$sql = sprintf("SELECT *
FROM SubCategoryLookup
WHERE LinkedCategoryID='%s' AND
OrganizationCode='%s'",
mysql_real_escape_string($CategoryId),
mysql_real_escape_string($OrganizationCode));
$query = mysql_query($sql);
// change $link to the name of your database connection variable
if (!$query)
die('Query failed (' . mysql_errno($link) . '): ' . mysql_error($link));
不再支持功能mysql_*
,它们已正式弃用,不再维护,将来将被删除。您应该使用PDO或MySQLi更新您的代码,以确保您的项目在未来的功能。
这就是您将得到的:
[{
"SubCategoryID": "8",
"LinkedCategoryID": "3",
"SubCategoryTitle": "Projects: Client A",
"SubCategoryAddedDateTime": "2013-07-12 23:16:25",
"SubCategoryAddedByUserID": "1",
"OrganizationCode": "celeritas"
}, {
"SubCategoryID": "9",
"LinkedCategoryID": "3",
"SubCategoryTitle": "Projects: Client B",
"SubCategoryAddedDateTime": "2013-07-12 23:16:25",
"SubCategoryAddedByUserID": "1",
"OrganizationCode": "celeritas"
}, {
"SubCategoryID": "10",
"LinkedCategoryID": "3",
"SubCategoryTitle": "Projects: Client C",
"SubCategoryAddedDateTime": "2013-07-12 23:16:25",
"SubCategoryAddedByUserID": "1",
"OrganizationCode": "celeritas"
}]