$sql="select * from `e_newsclass` where f_id=0 order by rank asc";
$query=$db->query($sql);
while($row_class=$db->fetch_array($query)){
$sqlz = " `e_newsclass` where f_id='$row_class[id]' order by rank asc";
$queryz=$db->findall($sqlz);
while($row_classz=$db->fetch_array($queryz)){
$sm_classz[]=array("name"=>$row_classz[name],"id"=>$row_classz[id]);
}
$sm_class[]=array("name"=>$row_class[name],"id"=>$row_class[id],"smClassz" =>$sm_classz);
unset($sm_classz);
}
$smarty->assign("sm_class",$sm_class);//导航引入 <ul id="nav">
<li class="jss"><a href="index.php">首页</a></li>
{section name=l loop=$sm_class}
<li><a href="class.php?cid=10">{$sm_class[l].name}</a>
<ul>
{section name=ll loop=$sm_class[l].smClassz}
<li><a href="class.php?cid=13&fid=10">{$sm_class[l].smClassz[ll].name}</a></li>
{/section}
</ul>
</li>
{/section}
</ul>
循环只输出一条信息 把第二层循环注释掉 第一层循环的数据都可以显示出来
请问怎么写才能实现这个功能 谢谢了 小弟新手困扰了一天了
在线求解 不明白的 加QQ308329547 或回帖询问
$query=$db->query($sql);
while($row_class=$db->fetch_array($query)){
$sqlz = " `e_newsclass` where f_id='$row_class[id]' order by rank asc";
$queryz=$db->findall($sqlz);
while($row_classz=$db->fetch_array($queryz)){
$sm_classz[]=array("name"=>$row_classz[name],"id"=>$row_classz[id]);
}
$sm_class[]=array("name"=>$row_class[name],"id"=>$row_class[id],"smClassz" =>$sm_classz);
unset($sm_classz);
}
$smarty->assign("sm_class",$sm_class);//导航引入 <ul id="nav">
<li class="jss"><a href="index.php">首页</a></li>
{section name=l loop=$sm_class}
<li><a href="class.php?cid=10">{$sm_class[l].name}</a>
<ul>
{section name=ll loop=$sm_class[l].smClassz}
<li><a href="class.php?cid=13&fid=10">{$sm_class[l].smClassz[ll].name}</a></li>
{/section}
</ul>
</li>
{/section}
</ul>
循环只输出一条信息 把第二层循环注释掉 第一层循环的数据都可以显示出来
请问怎么写才能实现这个功能 谢谢了 小弟新手困扰了一天了
在线求解 不明白的 加QQ308329547 或回帖询问
public function fetch_array() {
return mysql_fetch_array($this->result);
}/*数据库执行语句,可执行查询添加修改删除等任何sql语句*/
public function query($sql) {
if ($sql == "") {
$this->show_error("SQL语句错误:", "SQL查询语句为空");
}
$this->sql = $sql; $result = mysql_query($this->sql, $this->conn); if (!$result) {
//调试中使用,sql语句出错时会自动打印出来
if ($this->show_error) {
$this->show_error("错误SQL语句:", $this->sql);
}
} else {
$this->result = $result;
}
return $this->result;
}附上 数据库中的2个类
findall 方法是如何定义的?
我自己也是用smarty双循环输出二级菜单的时候,只能正常得到第一层数组
第二层显示不出来在php程序中打印数组可以得到正确结果,但smarty中却总是没有二级
对了,我还加了一个{if} {/if}判断是否有二级菜单,有才输出祝楼主好运,有高手来解答
you can access complex data structures, such as multi-dimensional
arrays. In this example, $contact_type[customer] is an array of
contact types for the current customer. *}
{section name=customer loop=$custid}
id: {$custid[customer]}<br>
name: {$name[customer]}<br>
address: {$address[customer]}<br>
{section name=contact loop=$contact_type[customer]}
{$contact_type[customer][contact]}: {$contact_info[customer][contact]}<br>
{/section}
<p>
{/section}
在定义一个 $db2;
用$db2->query();试试
$sql="select * from `e_newsclass` where f_id=0 order by rank asc";
$query=$db->query($sql);
while($row_class=$db->fetch_array($query)){
$sqlz = "select * from e_newsclass` where f_id='".$row_class[id]."' order by rank asc";
$queryz=$db->query($sqlz);
while($row_classz=$db->fetch_array($queryz)){
$sm_classz[]=array("name"=>$row_classz[name],"id"=>$row_classz[id]);
}
$sm_class[]=array("name"=>$row_class[name],"id"=>$row_class[id],"smClassz" =>$sm_classz);
unset($sm_classz);
}
$smarty->assign("sm_class",$sm_class);//导航引入 <ul id="nav">
<li class="jss"><a href="index.php">首页</a></li>
{section name=l loop=$sm_class}
<li><a href="class.php?cid=10">{$sm_class[l].name}</a>
<ul>
{section name=ll loop=$sm_class[l].smClassz}
<li><a href="class.php?cid=13&fid=10">{$sm_class[l].smClassz[ll].name}</a></li>
{/section}
</ul>
</li>
{/section}
</ul>
其实这个循环是对的,但是敝人发现你有一句话异常
$sqlz = " `e_newsclass` where f_id='$row_class[id]' order by rank asc";
应该是$sqlz="select * from e_newsclass where f_id='".$row_class[id]."' order by rank asc";吧,因为你根本没有获取查询的内容,那么下面就没有内容,自然循环不出来了!