Current location: Hot Scripts Forums » Programming Languages » PHP » Calling Latest record!!


Calling Latest record!!

Reply
  #1 (permalink)  
Old 11-15-03, 02:32 PM
Soulidified Soulidified is offline
Newbie Coder
 
Join Date: Jul 2003
Location: West Side
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Calling Latest record!!

Maybe you can show me? Below I pasted the code I am using, now this code allows me to call an id via ?id=id number). And this does work, it will grab an article and the corresponding comments. Now i want to call the "latest" article and corresponding comments. (note: that article and comments are on the same page) Thanks for your guys help once again.

<?


$db = mysql_connect ('localhost','user,'pass');
mysql_select_db ('databaselearndb',$db);


$query = "SELECT id,title,newstext," .
"DATE_FORMAT(postdate, '%Y-%m-%d') as date " .
"FROM news WHERE id='$id'";

$result = mysql_query ($query);
while($myrow = mysql_fetch_array($result))
{

echo "<TABLE border=\"1\" width=\"300\">\n";

/* place table row data in
* easier to use variables.
* Here we also make sure no
* HTML tags, other than the
* ones we want are displayed */
$date = $myrow['date'];
$title = htmlentities ($myrow['title']);
$news = nl2br (strip_tags ($myrow['newstext'], '<a><b><i><u>'));


echo "<TR><TD><b>$title</b> posted on $date</TD></TR>\n";
echo "<TR><TD>$news</TD></TR>\n";
}

$comment_query = "SELECT * FROM news_comments WHERE news_id='$id'";
$comment_result = mysql_query ($comment_query);
while($myrow = mysql_fetch_array($comment_result))
{



echo $myrow['COMMENT'];
echo "<br><br>";

}

?>

Can you edit (help me out) this? Thanks guys.
__________________
"Go Bigger"
Reply With Quote
  #2 (permalink)  
Old 11-16-03, 06:58 AM
Stefan's Avatar
Stefan Stefan is offline
Junior Code Guru
 
Join Date: Jun 2003
Location: Utrecht, The Netherlands
Posts: 599
Thanks: 0
Thanked 0 Times in 0 Posts
$query = "SELECT id,title,newstext," .
"DATE_FORMAT(postdate, '%Y-%m-%d') as date " .
"FROM news ORDER BY postdate LIMIT 1";

this should do the job.

of course, this does mean that you also will need to change the comments query to:

$comment_query = "SELECT * FROM news_comments WHERE news_id='".$myrow['id']."'";
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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 On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Need to pull LATEST record... any ideas? Soulidified PHP 4 11-14-03 04:11 PM
how do i add a record AND send an email in one step? nickleidecker ASP 2 10-14-03 07:12 PM
Calling pages with the .php?id="#" link Soulidified PHP 1 08-11-03 07:01 AM
Correctly calling a bash sub routine in php Archbob PHP 2 07-28-03 10:45 PM
selection of dup recs by latest date atworx Hot Scripts Forum Questions, Suggestions and Feedback 0 06-24-03 11:05 PM


All times are GMT -5. The time now is 05:46 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.