检索MySQL行键
问题描述:
我想从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函数,关键是关联的值?
答
看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
)
答
使用mysql_fetch_assoc
到获得结果的关联数组。这应该给你你想要的。
链接:http://www.php.net/manual/en/function.mysql-fetch-assoc.php