$sql = 'select id,name from user';$result = $db->query($sql);while($row=$db->getarray($result))
{
  
}数据库查询出来ID, NAME,传到smarty模板里
想如下这么输出<a href="a.php?ID=$ID">$name</a>也就是传个数列。
初学PHP,不知道该怎么做。就是想传个C里说的结构数组进去。
struct a
{
int a;
int b;
int c;
}
vector<a> m;数组成员保护多个成员。该怎么传进smarty模板里用呢?

解决方案 »

  1.   

    你要明白PHP是执行程序,smarty只是输出 ,所以程序就在PHP中写好$sql = 'select id,name from user';$result = $db->query($sql);
    $list=array();
    while($row=$db->getarray($result))
    {
      $list[]=$row;
    }
    $smarty->assign("list",$list);在模版中<?section name=loop loop=$list?>
    <a href="<?$list[loop].url?>"><?$list[loop].name?></a>
    <?/section?>