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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SublimeText3 English version
Recommended: Win version, supports code prompts!

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 Chinese version
Chinese version, very easy to use

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function