Hongmu Notes
Home Language Notes When sql statements are queried in, they are sorted according to the order in in.
Language Notes PHP mySql

When sql statements are queried in, they are sorted according to the order in in.

When sql statements are queried in, they are sorted according to the order in in.

Original SQL statement:

$sql=$empire->query("select classid,sonclass,classname,islast,islist from {$dbtbpre}enewsclass where classid in (1,22,239,241,75,80,45,62) and showclass=0 order by myorder,myorder asc");

Modified SQL statement:

$sql = $empire->query("  
    SELECT   
        classid,  
        sonclass,  
        classname,  
        islast,  
        islist   
    FROM   
        {$dbtbpre}enewsclass   
    WHERE   
        classid IN (1,22,239,241,75,80,45,62)   
        AND showclass=0   
    ORDER BY   
        FIELD(classid, 1, 22, 239, 241, 75, 80, 45, 62),  
        myorder ASC  
");

In an SQL query, if you want to filter results based onclassidINTo sort the elements in a clause by their order, you need to create a custom sorting logic.

For example, useCASEUse a statement to manually define a sorting rule.

微信赞赏

WeChat

支付宝赞赏

Alipay

✍️ Author: Hong Mu

webmaster · Thanks for reading, stay tuned for more exciting content

Author homepage View home page →

Related articles

PHP ob function record

PHP ob function record Language Notes PHP

Usage of the following three functions ob_get_contents(); ob_end_clean(); ob_start(); You can use these functions to buffer local files and execute local script code. Use ob_start() to save the output code into the buffer, and the page will not be displayed; then use ob_get_contents to get the data in the buffer. o…
👁 141
PHP preg

PHP preg Language Notes PHP

The preg_match_all function is used to perform a global regular expression match. preg_match_all() Syntax int preg_match_all ( string $pattern , string $subject [, array &$matches [, int $flags = PREG…
👁 169
Detailed explanation of PHP ternary operator and if

Detailed explanation of PHP ternary operator and if Language Notes PHP

Ternary operator condition ? Result 1 : Result 2 Explanation: The position in front of the question mark is the condition for judgment. If the condition is met, the result is 1, and if it is not met, the result is 2. This article compares and explains the ternary operator and if...else... in detail. I hope it will be helpful to everyone. Today when I was revising my paper online, I encountered a statement that I couldn’t understand: $if_summary = $row['IF_SUMMARY']=…
👁 189
PHP cast type

PHP cast type Language Notes PHP PHP collection PHP and mysql

Get the data type 1. If you want to check the value and type of an expression, use var_dump(). 2. If you just want to get an easy-to-read type expression for debugging, use gettype(). 3. To check a certain type, do not use gettype(), but use the is_type() function. Converting Strings to Numbers When a string is evaluated as a number, the result is determined according to the following rules...
👁 232

Recommended reading

unzip LinuxPanel.zip -bash: unzip: command not found

unzip LinuxPanel.zip -bash: unzip: command not found Summary of pitfalls

This error message is because the unzip command line tool is not installed in your Linux system. You can use the following command to install the unzip tool: For Debian/Ubuntu systems: sudo apt-get install unzip For CentOS/RHEL systems: sudo yum install unzip The installation is complete…
👁 188
(Adaptive Mobile Version) Swimming Pool Equipment – PBootCMS Website Template; Swimming Pool Water Treatment System Website Source Code Download – 0605

(Adaptive Mobile Version) Swimming Pool Equipment – PBootCMS Website Template; Swimming Pool Water Treatment System Website Source Code Download – 0605 Practical Collection pbootcms Template

A PbootCMS website template for swimming pool equipment and water treatment systems, compatible with mobile devices. The clean and professional design is ideal for showcasing swimming pool equipment, water treatment systems, and project cases. It helps swimming pool equipment companies showcase their products online and attract clients from hotels and sports venues. Template Display | Installation Instructions | Website Backend: /admin.php | Username: admin | Password: admin | Extraction Password: www.4s5....
👁 54
Responsive Hardware Manufacturing & Sheet Metal Processing Website Template 0030

Responsive Hardware Manufacturing & Sheet Metal Processing Website Template 0030 Practical Collection Yiyou template

This EyouCMS responsive template is ideal for hardware manufacturing and sheet metal processing enterprises. Its robust and professional design effectively showcases hardware products, sheet metal processing services, and industrial applications. It helps hardware manufacturers demonstrate their production capabilities online and attract potential customers. Template Display | Installation Instructions | Website Backend: /login.php | Username: admin | Password: admin | Related Articles: Summary of Common Installation Issues for EyouCMS | EyouCMS (...
👁 47
Mechanical Snow Removal Equipment Website Template 0652

Mechanical Snow Removal Equipment Website Template 0652 Practical Collection Yiyou template

An eyoucms website template for mechanical snow clearing equipment companies. The design style is professional and practical, and can display snow clearing equipment products, technical parameters, industrial applications and engineering cases. It helps machinery and equipment companies display their products online and attract municipal and property customers. Template display Installation instructions Website backend: /login.php Account: admin Password: admin Related articles Summary of common problems in Yiyou CMS installation Yi...
👁 37
Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, bool given in

Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, bool given in Language Notes PHP PHP and mysql

This warning typically indicates that your SQL query has failed, causing the `mysqli::query()` function to return the boolean value `false` instead of a valid `mysqli_result` object. This can occur for various reasons, such as: a syntax or logic error in the SQL query; the absence or unavailability of the target table or database; or an error during database connection (e.g., invalid credentials or hostname). To resolve this issue...
👁 1885