php smarty 如何綁定下拉框數據是從數據庫里取出來的

解决方案 »

  1.   


    <?php
    $smarty->assign("array",array());
    ?>//html.tpl
    <select>
    {foreach from=$array item=curr_id}
    < option >{$curr_id}</option>
    {/foreach}
    </select>
      

  2.   

    http://www.hbcms.com/main/smarty/language.function.foreach.html
      

  3.   


    <?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>
      

  4.   

    我现在是这样写的:
    $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}可是出來的結果不對,是不是我那個從數據庫取出來的值不是這樣寫的呢,求指點
      

  5.   

    取出來的結果只有兩條數據,而他卻有了四個選項,并且也不對
    <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
      

  6.   

    $total= mysql_fetch_array($result);
    这个你先赋值 $arr[]=$total;
    然后再循环添加!!! <section loop=$array name=test>
    <option value=$array[test][0]>$array[test][1]</option>
    </section>
      

  7.   

    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>