jQuery选择插件,从数据库中提取变量

时间:2011-02-23 21:46:31

标签: jquery

我正在使用此代码来生成动态选择: 演示:http://www.erichynds.com/examples/jquery-related-selects 代码:https://github.com/ehynds/jquery-related-selects

我更改了原始脚本的代码:

$counties = array();
$counties['1']['BARN'] = 'Barnstable';
$counties['1']['PLYM'] = 'Plymouth';
$counties['2']['CHIT'] = 'Chittenden';
$counties['3']['ANDE'] = 'Anderson';

$counties = array();
$sql = "SELECT
        id,
        naam,
        klant_id
        FROM contactpersoon
        ORDER BY klant_id ASC ";

if(!$res = mysql_query($sql,$con))
{
    trigger_error(mysql_error().'<br />In query: '.$sql);
}
else
{
    while ($row = mysql_fetch_array($res))
    {
        $counties[$row['klant_id'][$row['id'] =  htmlentities($row['naam']); 
    }
}

但由于某种原因,在进行更改时不会创建下拉选择列表。 当我测试查询时,没有显示错误。

1 个答案:

答案 0 :(得分:2)

至少在您发布的代码中存在错误。你的方括号似乎有点偏。

$counties[$row['klant_id'][$row['id'] =  htmlentities($row['naam']); 

应该是

$counties [$row['klant_id']] [$row['id']] =  htmlentities($row['naam']); 

$a = $row['klant_id'];
$b = $row['id'];
$counties[a][b]= htmlentities($row['naam']);