我正在使用 jqueryui 及其自动完成插件。它使用 json 来提取项目。
我想修改它,以便从我的数据库中提取项目。
物品应该是这样的:
$items = array(
"Great <em>Bittern</em>"=>"Botaurus stellaris",
"Great2 <em>Bittern</em>"=>"Botaurus stellaris 2"
);
如何创建一个从表中提取数据的 sql 查询并将其像上面的代码一样写入 php 文件中?
Table : customer
id_customer | name_customer | country_customer
我想要那个数组产生id_customer => name_customer
查询只是:
SELECT id_customer, name_customer FROM customer
你可以像这样生成数组(假设你正在使用 MySQL):
$items = array();
$result = mysql_query($sql);
while(($row = mysql_fetch_assoc($result))) {
$items[$row['id_customer']] = $row['name_customer'];
}
参考: MySQL SELECT syntax http://dev.mysql.com/doc/refman/5.5/en/select.html, mysql_query() http://php.net/manual/en/function.mysql-query.php, mysql_fetch_assoc() http://www.php.net/manual/en/function.mysql-fetch-assoc.php
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)