Smarty快速入门之三 填充Select元素
方法一:
<select id="province" name="province"><{html_options values=$province_values selected=$province_selected output=$province_output}>
</select>
</select>
php:
$query = mssql_execute($stmt, false);
while( $row= mssql_fetch_array($query) ){
$province_values[] =$row['ID'];
$province_output[] =$row['PName'];
}
$tpl->assign("province_values",$province_values);
$tpl->assign("province_output",$province_output);
$tpl->assign("province_selected",1);
方法二:
<select id="province" name="province">
<{foreach name=province_outer item=Item from=$source}>
<option value="<{$Item.ID}>"><{$Item.PName}></option>
<{/foreach}>
</select>
php:
$arr = array();
$query=mysql_query("select ID, PName from _T order by Orders",$conn);
while ( $row=mysql_fetch_array($query) ) {
$provinceId=$row['PID'];
$arr[$provinceId]['PID'] =$provinceId;
$arr[$provinceId]['PName'] =$row['PName'];
}
$tpl->assign('source',$arr);
Copyright © abandonship