dongtong848825 2012-01-13 13:21
浏览 25
已采纳

PHP mysql_query按顺序查看麻烦

I have mysql_query problem in php. Of course I have visitors in my website and they read football news there. The problem is that I try to sort news by views DESCending, but it doesn't work for new uploaded news. Somehow it appears at the end of the page. I've figured out one more thing that when views of the news is 9 it appears at the beginning of the page, but if it is more than 9 it appears at the end of the page. I'd appreciate any kind of help. Here is mysql_query.

mysql_query("SELECT * FROM news ORDER BY views DESC");

Oh and by the way, my website is http://www.bbcsport-football.com/football

there you can find Sorting options, New and Most Viewed. Click most viewed and you'll see it.

  • 写回答

3条回答 默认 最新

  • douou8954 2012-01-13 13:24
    关注

    You need to convert the views column to a number

    mysql_query("SELECT * FROM news ORDER BY cast(views as INTEGER) DESC")
    

    Or even better change the table definition so views is a INTEGER

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?