を使用して、配列の配列を取得するにはどのように、私は、クエリのmysqlから配列に値の配列を取得したいです。しかし、私はコンソールでチェック、私は配列のオブジェクトを取得します。私はサンプルのデータと私のクエリmysqlからのデータを使ってサンプルコードを書いていきます。私のjqueryのjqueryので
var locationsSample = [
[-6.175656, 106.812630,'ONSHORE',1,'id1'],
[-6.192848, 106.822027,'OFFSHORE',1,'id2'],
[-6.164234, 106.328973,'FABRICATION SHOP',1,'id3'],
[-0.594009, 100.735315,'SUMATERA',0,'id4'],
[5.168138, 97.124416,'SUMATERA ACEH',1,'id5']
];
console.log(locationsSample);
from console => Array [ Array[5], Array[5], Array[5], Array[5], Array[5] ] this is a true.
、これが私のPHPコードです:
ファイル名:jsonarray.php
$qry="SELECT latitude,longitude,project_name,status,id_tbl_project_map FROM tbl_project_map";
$res = mysql_query($qry) or die('Query failed: ' . mysql_error());
$rows= array();
while($data=mysql_fetch_assoc($res))
{
$rows[]=$data;
}
print json_encode($rows);
とjqueryのファイルjsonarray.php呼び出すために:ありがとう、
locations = new Array();
$.ajax({
url:"jsonarray.php?id=2",
type:"POST",
dataType:"json",
success:function(retqry){
locations = retqry;
console.log(locations);
from console => Array [ Object, Object, Object, Object, Object ] this is a false. why i'm get a Object not Array[5] from example code in top
}
});
が助けてください君は。
'Object'項目に正しいデータがありますか?あなたは 'mysql_fetch_assoc'とJSONをエンコーディングしているので、それをObjectとして解釈します。 (* mysqlは非推奨でセキュリティ上の欠陥があるので注意してください。*) –
コンソールでオブジェクトをクリックしてから、有効なデータまたはデータを表示してください。 –
彼らは正しいので、ここで間違ったことはありません。 PHPの連想配列項目がJSONのオブジェクトとして解釈されるため、なぜ最後のコメントの 'Object'であるのか説明しました。 –