静态数据很简单
$items = array( "Great Bittern"=>"Botaurus stellaris",
"Heuglin's Gull"=>"Larus heuglini" );
现在我想用数据库中的动态数据
来做这件事 $items = array();
do{
$items[] = $row_Recordset1['ID'] => $row_Recordset1['ARTIST'];
} while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));
它只使用了一个$ row_recordset,但当我把=>和第二个记录集,它给我一个错误
解析错误:语法错误,意外T_DOUBLE_ARROW
提前致谢
答案 0 :(得分:3)
应该如下:
$items = array();
while ($row = mysql_fetch_assoc($resource)) {
$items[$row['ID']] = $row['ARTIST'];
}
答案 1 :(得分:1)
选项1
$items[$row_Recordset1['ID']] = $row_Recordset1['ARTIST'];
或者
$items[] =array($row_Recordset1['ID'] => $row_Recordset1['ARTIST']);