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"
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
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