返回SQL查询为数组 [英] Return sql query as array
本文介绍了返回SQL查询为数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用jqueryui及其自动完成插件.它使用json提取项目.
I'm using jqueryui and its Autocomplete plugin. It use a json to extract items.
我想对其进行修改,以便从数据库中提取项目.
I want to modify it so that items will be extracted from my db.
这里是物品的样子:
$items = array(
"Great <em>Bittern</em>"=>"Botaurus stellaris",
"Great2 <em>Bittern</em>"=>"Botaurus stellaris 2"
);
如何进行从表中提取数据并将其像上面的代码一样写入php文件的sql查询?
How to make an sql query that extract data from a table and write it like the code above into the php file ?
Table : customer
id_customer | name_customer | country_customer
我希望该数组产生id_customer => name_customer
推荐答案
查询只是:
SELECT id_customer, name_customer FROM customer
,您可以像这样生成数组(假设您使用的是MySQL ):
and you can generate the array like so (assuming you are using MySQL):
$items = array();
$result = mysql_query($sql);
while(($row = mysql_fetch_assoc($result))) {
$items[$row['id_customer']] = $row['name_customer'];
}
参考文献: MySQL SELECT
语法, mysql_query()
, mysql_fetch_assoc()
References: MySQL SELECT
syntax, mysql_query()
, mysql_fetch_assoc()
这篇关于返回SQL查询为数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文