Sort record through PHP


The feedback list must have displayed but your client may still complain, if he or she has to scroll down all the time to see the most recent feedback post, instead of seeing the most recent at the top of the list. This is also what your yahoomail does, it ordered the most recent email to be on top in your box.
To do this we just need to alter the SELECT statement to ORDER its result in DESC (descending order)  below is what the line of code should look like.

Before (Note: by default it’s ordered in ascending)
$query  = "SELECT * FROM feedback";

$query  = "SELECT * FROM feedback ORDER BY id DESC";

This will order the record to display in descending order. I ordered the record using the id field because it contain auto-generated ascending numbers. 

The screenshot should now look like what we have below.


Now let’s continue, but still on better way of displaying or viewing queried records.


Next »

Return to PHP Sample Main Page