啊小弟我被递归给郁闷死了.请大家帮小弟我一下

WBOY
Release: 2016-06-13 12:17:29
Original
843 people have browsed it

紧急求助啊.我被递归给郁闷死了.请大家帮我一下

首先.我的[栏目]表结构是这样的
id   uid   titile  class
1    0       首页  url
2   0       新闻  news
3   0       产品  url
4   3      科技产品  product
5   4      电脑   product

现在的问题的  我想做一下 无限级的下拉框

用递归的方法,可以实现  where  uid = 0  开始循环  然后 get_str($row['id']); 递归


但是问题来了.  因为我的栏目 有一个CLASS字段  表示栏目类型...url表示外部链接  news表示新闻 product表示产品栏目

一级产品首先是一个外部链接类型的..他的下级栏目 是产品类型的
我在后台发布产品的时候.选择归属栏目的时候..............应该只把 class=prodcut和他的下级全部显示出来
那么我用递归的方法  在SQL加上条件语句  where class='product'

这样的话 没办法往下递归啊......  因为这个条件 如果不递归的话 就显示  科技产品    电脑

我在网上找的归递代码 都是UID 从 0开始的..........如果我  where class='product' 加上这个条件   那么科技产品的UID是3或者是其它数字 比如56789 也可能是0

这样就没办法递归啊...直接什么也不显示了...有什么好法方吗? 不知道我说的清不清楚.
------解决思路----------------------

function foo($uid=0, $ext='') {<br />  $sql = "select * from tbl_name where uid=$uid" . ($uid && $ext ? " and class='$ext'" : '');<br />  $rs = mysql_query($sql);<br />  while($row = mysql_fetch_assoc($rs)) {<br />    foo($row['id'], $ext);<br />  } <br />}
Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!