Page 1 of 1
display in sorted order from DB
Posted: Tue Jan 10, 2012 2:06 pm
by inosent1
i want to have the data displayed from the DB sorted in a particular way. right now i call the data from the DB and it displays in the order of the table, and then use a javascript header gizmo to sort.
but i would rather the data show up sorted in the first place and use the js sort when i need to.
Re: display in sorted order from DB
Posted: Tue Jan 10, 2012 2:13 pm
by twinedev
Code: Select all
$sql = 'SELECT `field1`, `field2` FROM `tblStuff` WHERE `category` = "'.mysql_real_escape_string($strFilter).'" ORDER BY `field3` ';
For decending order:
Code: Select all
$sql = 'SELECT `field1`, `field2` FROM `tblStuff` WHERE `category` = "'.mysql_real_escape_string($strFilter).'" ORDER BY `field3` DESC ';
You can sort on more than one field, separate them by commas. Note the ASC (default if not given, as in first example above) or DESC needs to be with each field:
Code: Select all
ORDER BY `field1` DESC, `field2` ASC
-Greg
Re: display in sorted order from DB
Posted: Tue Jan 10, 2012 2:19 pm
by inosent1
thanks!