This is a discussion on Grab 1 record (latest Date) from MySQL db within the PHP General forums, part of the PHP Programming Forums category; Hi all: Relative newbie here. I have no problem creating the "News" database, displaying all records but I ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hi all:
Relative newbie here. I have no problem creating the "News" database, displaying all records but I want to only grab the latest "Date" (db column name = TimeStamp, datatype = Date). Here is the successfull code to grab all records (and reformat date) but for some reason I cant seem to get the syntax right for the latest dated one: db News table structure = id(int), nTitle(text), nBody(text), TimeStamp(Date) <?php // Set the variables for the database $Host = "myhost"; $User = "myuser"; $Password = "myserver"; $DBName = "mydb"; $TableName = "News"; $Link = mySql_connect ($Host, $User, $Password); //$Query = "Select * from $TableName ORDER BY TimeStamp DESC, LIMIT 1" ; /This for latest date? $Query = "Select * from $TableName ORDER BY TimeStamp DESC" ; //This gets all $Result = mySql_db_query ($DBName, $Query, $Link); //print results while ($Row = mySql_fetch_array ($Result)) { $formatted_date = date('F jS, Y',strtotime($Row[TimeStamp])); print("$formatted_date - \n"); print("$Row[nTitle]<BR>\n"); } mySql_close ($Link); ?> My guess is I dont need the "while" statement, but when I remove it everything breaks. Thanks in advance for anyones help. Eric B |