2011-02-28 101 views
1

我想從MySQL數據庫中檢索一行,例如,使用相應的鍵返回一行。眼下,檢索行時印刷這樣簡單地給出了PHP的數組:檢索MySQL行鍵

Array 
(
    [0] => 15 
    [1] => 2011-02-27 22:31:46 
    [2] => salmon-with-pineapple-curry-sauce-photo_0.jpg 
    [3] => 1 
    [4] => Salmon Fillet 
    [5] => Trader Joes 
    [6] => So delicious 
    [7] => 5 
    [8] => 35.282753 
    [9] => -120.659615 
) 

我怎麼會找回所以,關鍵是該領域的數據庫名稱,這樣,當我去使用json_encode函數,關鍵是關聯的值?

回答

1

mysql_fetch_assoc()返回的行與數據庫表字段建立索引

輸出數組的數組看起來像這樣

Array 
(
    ['id'] => 15 
    ['date'] => 2011-02-27 22:31:46 
    ['name'] => salmon-with-pineapple-curry-sauce-photo_0.jpg 
    ..... 
    .....//other elements or fields 
)