Bluehost.com Web Hosting $6.95

Grab 1 record (latest Date) from MySQL db

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 ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 11-23-2003
Eric B
 
Posts: n/a
Default Grab 1 record (latest Date) from MySQL db

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
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 05:03 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0