2015-12-23 71 views
0

這是我的代碼,實際上我在json編碼數據中插入一個數組並通過jquery返回。從json編碼獲取php數組值jquery

 $list_type_query = "select * from assettype"; 
     //the asset type table contains (id & type) column 
     $query = mysqli_query($conn, $list_type_query); 
     while($r = mysqli_fetch_array($query)){ 
      $result_value = array("Status" => "haslist", "list" => $r); 
     } 

這是jquery的一面。 $('#sh')是一個div,我需要在div內顯示所有類型的內容。

如果我使用數據[ '列表'] [0] [ '型']我得到一個對象0值。

如何以div動態顯示所有值。

回答

0

我認爲這個問題在你的php代碼中。 因爲在每個循環中,$ r只獲取當前所有的索引數據,而$ result_value只獲取當前的索引數據。

你可以試試這個...

$list_type_query = "select * from assettype"; 
    //the asset type table contains (id & type) column 
    $query = mysqli_query($conn, $list_type_query); 
    $all_data = array(); 
    while($r = mysqli_fetch_array($query)){ 
     $all_data[] = $r; 
    } 
    $result_value = array("Status" => "haslist", "list" => $all_data); 
+0

我geeting結果在陣列狀物體{狀態: 「haslist」,列表:數組[6]} –

+0

和列表數組列表:數組[6] 0:對象 1:對象 2:對象 3:對象 4:對象 5:對象 –

+0

我需要如何顯示在汽車的div的所有的對象數據,而無需手動給予任何對象。 –