我从网站上获取此代码,我正在尝试将其定制到我的测试脚本中。而不是zip,city,state我想显示company_name。我怎么修改这个?
PHP:
$rs = mysql_query('select company_name from names_of_companies where
company_name like "'. mysql_real_escape_string($_REQUEST['term']) .'%"
order by company_name asc limit 0,10', $dblink);
$data = array();
if ( $rs && mysql_num_rows($rs) )
{
while( $row = mysql_fetch_array($rs, MYSQL_ASSOC) )
{
//This is the part where instead of displaying zip, city, state
I only want company_name, how can i do that?
$data[] = array(
'label' => $row['zip'] .', '. $row['city'] .' '. $row['state'] ,
'value' => $row['zip']
);
}
}
答案 0 :(得分:3)
我认为这就是你想要的循环:
//I only want company_name, how can i do that?
$data[] = array('label' => 'Company_name', 'value'=> $row['company_name'] );
但是如果你很难搞清楚这个,那么你将有时间做正确的事情......我建议退一步,熟悉PHP。< / p>
答案 1 :(得分:1)
while( $row = mysql_fetch_array($rs, MYSQL_ASSOC) )
{
...
'company_name' => $row['company_name']; // this is what you want
...
请注意:引自mysql_fetch_array
手册:
不鼓励使用此扩展程序。取而代之的是MySQLi或PDO_MySQL 应该使用扩展名。另见MySQL:choosing an API guide和 相关FAQ以获取更多信息。替代此功能 包括: