dtnat80842 2016-11-22 14:43
浏览 17
已采纳

在PHP中排序重复[重复]

This question already has an answer here:

I have a website with a database over different phones. And to gather data from the database, I have this code

//echo "SELECT * FROM `product_info` DESC";die;
    $filter = $this->queries->custom("SELECT * FROM `product_info`GROUP BY 'model' ORDER BY  `model` ASC");

When I use this code now, it only shows one model, instead of all the different models.

Since i've added some of the models more than once i Would like to sort those out.

Like, i have fx added the iPhone 7 5 different times in my database and of course i wouldn't want the site to show it 5 times, therefore i would like to sort after models and only show each model one time. I've read about the array_unique, but didn't quite understand it.

</div>
  • 写回答

2条回答 默认 最新

  • dongwei4444 2016-11-22 15:36
    关注

    I guess I found the problem, it's a little typo. You used single quotes ( ' ) instead of backticks ( ` ) for your GROUP BY column. Single quotes are for string values. This means that your current query groups by the string "model" (and not by the column model), which is of course the same string for every record.

    So either use backticks:

    SELECT * FROM `product_info` GROUP BY `model` ORDER BY `model` ASC
    

    or omit the backticks at all because they are only necessary when your column is a reserved keyword:

    SELECT * FROM product_info GROUP BY model ORDER BY model ASC
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)