这似乎是一个愚蠢的问题,但经过长时间的搜索,我被难住了。
我正在使用查询来检索数据,然后编码为 JSON,以便在我的站点周围的各个地方使用。只有一个问题。我似乎无法检索数据!
查询(data.users.php):
$arr = array();
$rs = mysql_query("SELECT
CONCAT(m.firstName,' ',m.lastName) AS name,
m.email,
m.permission,
m.costRate,
m.dt,
m.memberID,
m.moduleFinancial,
o.orgName
FROM members m
LEFT JOIN organisations o ON m.organisationID = o.organisationID
WHERE status = 'true'
ORDER BY name"
) or die(mysql_error());
while($obj = mysql_fetch_object($rs)) {
$arr[] = $obj;
}
header("Content-type: application/json");
echo json_encode($arr);
数据示例:
[{"name":"Admin User","email":"test@test.com","permission":"admin","dt":"2013-02-02 10:26:29","memberID":"M0000001"},{"name":"Another User","email":"another@test.com","permission":"admin","dt":"2012-02-02 10:26:29","memberID":"M0000002"}]
有任何想法吗?
更新获取代码:
ob_start();
include("../data/data.users.php");
$arr = json_decode(ob_get_clean(), true);
foreach($arr as $item) {
if ($item['memberID'] == $_GET["ID"]) {
$user_name = $item['name'];
}
}