PHP中使用MySQL按照多字段排序及问题解决
因为在做一个项目需要筛选掉一部分产品列表中的产品,使其在列表显示时排在最后,但是所有产品都要按照更新时间排序。
研究了一下系统的数据库结构后,决定将要排除到后面的产品加为粗体,这样在数据库中的“ifbold”就会被标记为1,而其他产品就默认标记为0,然后就打算使用MySQL在Order By时进行多字段排序。
Orderby的多条件分割一般使用英文逗号分割,所以我测试的SQL如下:
select * from {P}_product_con where $scl order by 'ifbold' asc,$myord desc limit $pagelimit"
但是运行后没有将”ifbold“正序,但是单纯正序”ifbold“却正常,调试了N久,无意中在phpMyAdmin中运行却发现正常,仔细比对后发现问题原来是来自于”ifblod“的引号上。改为下列语句就正常了:
select * from {P}_product_con where $scl order by `ifbold` asc,$myord desc limit $pagelimit
所以以后大家再程序中写SQL语句时也要注意引号的问题哦!
本文来源:http://blog.yourtion.com

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Chinese version
Chinese version, very easy to use

WebStorm Mac version
Useful JavaScript development tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver Mac version
Visual web development tools
