怎么取数据库里的值?
数据库如下。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中怎么实现?
每个大类下,跟着他的小类作为一条数据,建个新表。
------解决方案--------------------
<br />$sqlstr = "select * from table where id<6";<br />$query = mysql_query($sqlstr) or die(mysql_error());<br />while($thread=mysql_fetch_array($query)){<br /> $result[] = $thread;<br />}<br />print_r($result);<br />
建议一开始建立表结构的时候考虑下无限级分类;然后把你这个表好好优化下那样获取就更好了。select cate1, group_concat(cate2) as cate2 from tbl_name where cate2!='' group by cate1 order by id
<br /> cate1 cate2 <br />Protect Power Bank Protectio,Table Protection,Phone Case <br />Power Wall Charger,Car Charger,Power Bank <br />Keyboard&Mouse Mouse,Keyboard <br />Headphone Bluetooth Headphone,Earphone,Headphone <br />Bluetooth_Speaker Wall Charger,Car Charger,Power Bank <br />
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号