<?php
$username = "trainerapp";
$password = "password";
$hostname = "localhost";
$link = @mysql_connect($hostname, $username, $password);
if (@mysql_select_db("trainer_registration")) {
$select_query_num = @mysql_query("select id from program_details");
$num_rows = @mysql_num_rows($select_query_num);
while ($row = @mysql_fetch_assoc($select_query_num)) {
$j = $row['id'];
$select_query = @mysql_query("select id,program_name,company,date_prog from program_details where id = $j");
$fetch_query = @mysql_fetch_assoc($select_query);
$id = $fetch_query['id'];
$pgmname = $fetch_query['program_name'];
$comp = $fetch_query['company'];
$datephp = $fetch_query['date_prog'];
$arr[] = array(
$id,
$pgmname,
$comp,
$datephp
);
}
echo json_encode($arr);
}
?>
CURRENT OUTPUT:
[["1","Sample","Apple","2015-05-27"],["2","Sample 2","Lenovo","2015-05-28"],["14","3","3","09-29-2015"]]
我不明白这个输出。
问题:
json_encode实际返回了什么?由&#39;,&#39;?分隔的所有值的字符串或数组因为当我在js文件中尝试str.length()时,它返回了126
如何获得单行输出
["1","Sample","Apple","2015-05-27"]
["2","Sample 2","Lenovo","2015-05-28"]
["14","3","3","09-29-2015"]
在javascript中的数组中,因为我需要在单独的列下的html中插入它们。即,列#34; ID&#34;下的1,2,14,样本,样本2,3,列#34;程序名称&#34;,依此类推。 请帮助解析这个数组。
答案 0 :(得分:-1)
1 - http://php.net/manual/en/function.json-encode.php所有人都在那里。
2 - Convert php array to Javascript它会对你有帮助。
3 - 如果您需要一个数组,为什么在代码中使用json_encode。
4 - 你知道为什么在很多地方使用let pred = NSPredicate(format: "content IN %@ AND (tallied == 0 OR comment != '')", arr)
let query = CKQuery(recordType: "Rating", predicate: pred)
?像这样的代码真的很糟糕。