43243

来源:互联网 发布:壹卡会可以在淘宝用吗 编辑:程序博客网 时间:2024/05/19 05:29
<pre name="code" class="php"><?php/*@author 月之鹰 *无限级分类实现 */$wx = mysql_connect('localhost','root','root') or die(mysql_error());mysql_select_db('test',$wx) or die(mysql_error());mysql_query("set names 'utf8'");function getLists($pid=0,&$lists=array(),$level=1){$sql="select * from wx where pid=".$pid;$res=mysql_query($sql);while($row=mysql_fetch_assoc($res)){$row['name'] = str_repeat('--',$level).'|'.$row['name'];$lists[]=$row;getLists($row['id'],$lists,$level+2);}return $lists;}function displayLists($pid=0){$result=getLists($pid);foreach($result as $v){echo $v['name'].'<br/>';}}displayLists();


create table wx(id int(10) not null primary key auto_increment,pid int(10) not null,name varchar(50) not null)charset utf8;




0 0
原创粉丝点击