[GLLUG] More MySQL

Dpk dpk@egr.msu.edu
Tue, 19 Mar 2002 13:20:11 -0500


On Tue, Mar 19, 2002 at 01:15:51PM -0500, Mike Szumlinski wrote:

   Thanks to all that answered my last 5 or so devel questions.  I
   have a new one. I'm creating a new table that I want to use as a
   "what's new" storage container, so it will basically have just a
   timestamp, a poster name, and the message data. I want to sort
   these things on the page with the most recent date first. Normally
   I do this in php:
   
   $query = mysql_query("SELECT date_format(dateadded, '%M %d, %Y') AS
   Readable_Date from mytable",$db);
   
   And then:
   
   while ($daterow = mysql_fetch_row($query))
   {printf("$daterow[0]<br>")}
   
   This prints out the dates of my entries in chronological order,
   from oldest to newest. Does anyone know how to do this? Am I just
   an idiot and using poor poor poor coding methodology (probably).
   
   Thanks again to all that have been helping me here.

You are headed on the right track... use a timestamp field that will
default to the current time upon insert/update.

You can then do something like "SELECT data FROM table ORDER BY
timestamp" 

Dennis