php smarty 如何綁定下拉框 php smarty 如何綁定下拉框數據是從數據庫里取出來的 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <?php$smarty->assign("array",array());?>//html.tpl<select>{foreach from=$array item=curr_id} < option >{$curr_id}</option>{/foreach}</select> http://www.hbcms.com/main/smarty/language.function.foreach.html <?php$array = array(array(0,'lishi'));$smarty->assign("array",array());?>//html.tpl<select>{section loop=$array name=arr} < option value='{$array[arr][0]}'>{$array[arr][1]}</option>{/section}</select> 我现在是这样写的:$sql="select id,name from tb where pid=0 ";$result=mysql_query($sql);$total= mysql_fetch_array($result);$smarty->assign ( "total", $total );{section loop=$total name=arr} < option value='{$total[arr][0]}'>{$total[arr][1]}</option>{/section}可是出來的結果不對,是不是我那個從數據庫取出來的值不是這樣寫的呢,求指點 取出來的結果只有兩條數據,而他卻有了四個選項,并且也不對<select name="pid"> <option value="0">一級類別</option> <option value='3'></option> <option value='t'>e</option> <option value=''></option> <option value=''></option></select>這是頁面顯示的源代碼,而且數據庫的結果是id type title addUser addDate orderID pID3 1 test1 a 2010-11-17 1 04 1 test2 1 2010-11-17 1 07 0 3 3 2010-11-17 1 0 $total= mysql_fetch_array($result);这个你先赋值 $arr[]=$total;然后再循环添加!!! <section loop=$array name=test><option value=$array[test][0]>$array[test][1]</option></section> while ($row = mysql_fetch_array($result)) { $array[]=$row;}$smarty->assign("total",$array);//html.tpl<select>{section loop=$total name=arr} < option value='{$total[arr].id}'>{$total[arr].title}</option>{/section}</select> XML转义字符问题 php.ini的问题 关于一个preg_replace 正则表达式 替换的问题 报Fatal error: Call to undefined function mcrypt_get_block_size()错误如何解决? 怎样格式化一段代码... 请教一个使用PEAR的DB中很奇怪的问题 phpmyadmin登陆问题?急急 php怎样实现文件上传? 高人救命,php访问mysql死活不里我 debugger_on() 怎么不能用 这段AJAX代码应该怎么写更好?我写的有问题! 如何打印中数据库服务器上的所有数据库名称?
<?php
$smarty->assign("array",array());
?>//html.tpl
<select>
{foreach from=$array item=curr_id}
< option >{$curr_id}</option>
{/foreach}
</select>
<?php
$array = array(array(0,'lishi'));
$smarty->assign("array",array());
?>//html.tpl
<select>
{section loop=$array name=arr}
< option value='{$array[arr][0]}'>{$array[arr][1]}</option>
{/section}
</select>
$sql="select id,name from tb where pid=0 ";
$result=mysql_query($sql);
$total= mysql_fetch_array($result);$smarty->assign ( "total", $total );{section loop=$total name=arr}
< option value='{$total[arr][0]}'>{$total[arr][1]}</option>
{/section}可是出來的結果不對,是不是我那個從數據庫取出來的值不是這樣寫的呢,求指點
<select name="pid"> <option value="0">一級類別</option>
<option value='3'></option>
<option value='t'>e</option>
<option value=''></option>
<option value=''></option>
</select>
這是頁面顯示的源代碼,而且數據庫的結果是
id type title addUser addDate orderID pID
3 1 test1 a 2010-11-17 1 0
4 1 test2 1 2010-11-17 1 0
7 0 3 3 2010-11-17 1 0
这个你先赋值 $arr[]=$total;
然后再循环添加!!! <section loop=$array name=test>
<option value=$array[test][0]>$array[test][1]</option>
</section>
$array[]=$row;
}
$smarty->assign("total",$array);//html.tpl
<select>
{section loop=$total name=arr}
< option value='{$total[arr].id}'>{$total[arr].title}</option>
{/section}
</select>