自己写的无限分类
时间:2011-02-28 来源:windstudio
`id` tinyint(8) NOT NULL AUTO_INCREMENT,
`pid` tinyint(8) NOT NULL DEFAULT '0',
`name` char(12) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=14 ;
php代码如下:
$conn=mysql_connect('localhost','root','root'); mysql_select_db('test',$conn); mysql_query('set names utf8'); classing($result); print_r($result); function classing(&$child,$id=0) { $sql="select * from classing where pid=$id"; $res=mysql_query($sql); if(mysql_num_rows($res)==0) { return array(); } while($row=mysql_fetch_array($res)) { classing($child[$row['name']],$row['id']); } }
程序运行结果:
Array ( [动物世界] => Array ( [家畜] => Array ( [猪] => [牛] => ) [野生] => ) [植物世界] => Array ( [树木] => Array ( [桃树] => ) [花草] => Array ( [玉兰花] => Array ( [测试1] => [测试2] => ) [水仙花] => ) ) )
基本功能得实现...
相关阅读 更多 +