Home > Backend Development > PHP Tutorial > Using MySQL in PHP to sort by multiple fields and solve problems_PHP tutorial

Using MySQL in PHP to sort by multiple fields and solve problems_PHP tutorial

WBOY
Release: 2016-07-21 14:58:33
Original
763 people have browsed it

Because when working on a project, it is necessary to filter out some products in the product list so that they are ranked last when the list is displayed, but all products must be sorted according to update time.

After studying the database structure of the system, I decided to add bold font to the products to be excluded, so that "ifbold" in the database will be marked as 1, while other products will be marked as 0 by default, and then Plan to use MySQL to perform multi-field sorting during Order By.

Orderby’s multi-condition split generally uses English commas to split, so the SQL I tested is as follows:

select * from {P}_product_con where $scl order by 'ifbold' asc,$myord desc limit $pagelimit"
Copy after login

However, after running, "ifbold" was not in positive sequence, but the simple positive sequence "ifbold" was normal. After debugging for a long time, I accidentally ran it in phpMyAdmin and found that it was normal. After careful comparison, I found that the problem originally came from " ifblod" in quotes. Change it to the following statement and it will be normal:

select * from {P}_product_con where $scl order by `ifbold` asc,$myord desc limit $pagelimit
Copy after login

So in the future, everyone should pay attention to the quotation marks when writing SQL statements in programs!

Source of this article: http://blog.yourtion.com

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/363830.htmlTechArticleBecause when working on a project, it is necessary to filter out some products in the product list so that they are ranked last when the list is displayed. , but all products must be sorted by update time. I studied the system...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template