index.php
=======================
    require("smarty_inc.php"); //smarty_inc.php是smarty的配置信息
    
    
    $link = mysql_connect("localhost","root","root");
    mysql_select_db("test");
    $sql = "select id,name,password from admin";
    $result = mysql_query($sql,$link);
    $row = mysql_fetch_array($result, MYSQL_ASSOC);    $smarty->assign("name",$row);
    $smarty->display("index.htm");
index.htm
==============================
    {section name=option loop=$name}
        {$name[option].id}<br>
        {$name[option].name}<br>
        {$name[option].password}<br>
    {/section}为何这样页面显示无内容,而我用foreach就可正确循环.
请各路高手帮忙

解决方案 »

  1.   


    楼主  $row = mysql_fetch_array($result, MYSQL_ASSOC); 是生成关联数组,关联数组是用字段名索引的吧。你可以改成$row = mysql_fetch_array($result, MYSQL_NUM);或者$row = mysql_fetch_array($result, MYSQL_BOTH);或者$row = mysql_fetch_array($result);试试
    或者你直接用$row = mysql_fetch_row($result)
    估计是因为{section}循环的时候要用数字进行索引导致的,总之楼主先试试吧。   
      

  2.   

    section name=option 
    把NAME改成别的看看
      

  3.   

    1.把$row用var_dump打出来看看是都什么内容。
    2.是否是smarty缓存的问题,清理一下看看。