2011-09-02 32 views
-1

我從查詢中找回兩行,我在phpadmin中測試了它。json不會從數據庫數組中返回正確的結果

在firebug中,我只能看到一行中的數據。

什麼可能是錯誤的,我沒有看到?

$data = mysql_fetch_assoc($r); 

     } 
    } 

    header('Content-type: application/json');   
    $output = array(
    "check" => $check, 
    "users" => $data, 
    "testnumberoffrows" => $number 
    ); 

    echo json_encode($output); 
在ajaxfunction

if(data.check){ 
    var user = data.users; 
    console.log(user); 

感謝

,理查德

回答

1

mysql_fetch_assoc()只獲取一個一行。你需要循環,直到它返回FALSE,建立一個輸出數組。

事情是這樣的:

while (($row = mysql_fetch_assoc($r)) !== FALSE) { 
    $data[] = $row; 
} 
+0

感謝,我完全錯過了,我給自己headeaches – Richard

1

請嘗試

$got=array(); 
    while ($row = mysql_fetch_array($r)) { 
     array_push($got, $row); 
    } 

    mysql_free_result($r); 

    header('Content-type: application/json');    
    $output = array( 
     "check" => $check, 
     "users" => $data, 
     "testnumberoffrows" => $number 
    ); 

    echo json_encode($output);