脚本宝典收集整理的这篇文章主要介绍了PHP和MYSQL:使用group by作为类别,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
PRoductid | productname | category id
我想像这样输出它们:
category #1 ITem 1 item 2 item 3 category #2 item 1 item 2 item 3
<?PHP $stmt = $pdo-> query("SELECT * From `myTable` ORDER BY categoryID"); $current_cat = null; while ($row = $stmt->fetch()) { if ($row["categoryID"] != $current_cat) { $current_cat = $row["categoryID"]; echo "Category #{$current_cat}\n"; } echo $row["productName"] . "\n"; } ?>
以上是脚本宝典为你收集整理的PHP和MYSQL:使用group by作为类别全部内容,希望文章能够帮你解决PHP和MYSQL:使用group by作为类别所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。