Page 1 of 1

How do I sort mysql table result in ORDER BY 2 columns

Posted: Thu May 21, 2015 7:49 am
by adsegzy
Hello Friends,

I have a products table with several columns. On my Home page I want to display 30 items at random but all new Items to come first. Below are the codes I tried.

Code: Select all

$sql = mysql_query("SELECT * FROM products WHERE status='Online' && nature='Yes' ORDER BY RAND() LIMIT 5"); //FOR ONLY NEW ITEMS

$sql = mysql_query("SELECT * FROM products WHERE status='Online' && nature!='Yes' ORDER BY RAND() LIMIT 35"); //FOR OTHER ITEMS
How do I make them into one line.

Thanks

Re: How do I sort mysql table result in ORDER BY 2 columns

Posted: Thu May 21, 2015 11:26 am
by requinix
If "nature" is either Yes or No (not a great scheme, by the way) then you can sort by nature descending first and rand() second. That will order the "Yes"es before the "No"s.