数据库如下。cate1是大类。每个大类下又有小类。
怎么查找才能得到以下结果
id cate1
1 Protect Phone Case Table Protection Power Bank Protection
2 Power Power Bank Car Charger Wall Charger
3 Keyboard&Mouse Keyboard Mouse
4 Headphone Headphone Earphone Bluetooth Headphone
5 Bluetooth_Speaker Power Bank Car Charger Wall Charger
用sql语句怎么实现?在php中怎么实现?
每个大类下,跟着他的小类作为一条数据,建个新表。
回复讨论(解决方案)
$sqlstr = "select * from table where id<6";$query = mysql_query($sqlstr) or die(mysql_error());while($thread=mysql_fetch_array($query)){ $result[] = $thread;}print_r($result);
建议一开始建立表结构的时候考虑下无限级分类;然后把你这个表好好优化下那样获取就更好了。
select cate1, group_conca<div style="color:transparent">!本文来源gaodai.ma#com搞#代!码(网</div><em>搞gaodaima代码</em>t(cate2) as cate2 from tbl_name where cate2!='' group by cate1 order by id
cate1 cate2 Protect Power Bank Protectio,Table Protection,Phone Case Power Wall Charger,Car Charger,Power Bank Keyboard&Mouse Mouse,Keyboard Headphone Bluetooth Headphone,Earphone,Headphone Bluetooth_Speaker Wall Charger,Car Charger,Power Bank
无限级分类要怎么做,该怎么优化?
cate2中的数据怎么提取成单个的结果,以逗号为界。
无限级分类要怎么做,该怎么优化?
cate2中的数据怎么提取成单个的结果,以逗号为界。
可以去php基础 已解决模块 有xu老大,专门讲解无限极分类