printing last 3 db entries

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
fariquzeli
Forum Contributor
Posts: 144
Joined: Mon Jun 24, 2002 9:16 am
Location: Chicago
Contact:

printing last 3 db entries

Post by fariquzeli »

how do you get the last 3 db entries to be printed out. I have the mysql_fetch_array function, but i'm only sure on how to print out the field entries for one row, does anyone have a really generic example or a good bit of code to work off of?

another problem is that i will be parsing this inside of some javascript (if that's possible)
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

What does your code currently look like?

Mac
fariquzeli
Forum Contributor
Posts: 144
Joined: Mon Jun 24, 2002 9:16 am
Location: Chicago
Contact:

Post by fariquzeli »

Code: Select all

<?php require_once('Connections/ydntNews.php'); ?>
<?php
mysql_select_db($database_ydntNews, $ydntNews);
$query_news = "SELECT * FROM news ORDER BY id DESC";
$news = mysql_query($query_news, $ydntNews) or die(mysql_error());
$row_news = mysql_fetch_assoc($news);
$totalRows_news = mysql_num_rows($news);

$i = 0;
do &#123;
echo("messages&#1111;$i-1]='<font face=verdana color=#ffffff size=1>$row_news&#1111;'headline']</b><br> :<a href=http://www.yiinc.com/news.php?id=$row_news&#1111;'id']><font color=#cccccc>Full Story</a></font>");
$i++;
&#125;
while ( $i < 3 );
?>
the reason for the messages[]= is because this is going to be used within a javascript, and the $i-1 is so that it uses the proper javascript message id, i know the formatting is terrible and i dont know how to format it better, here is the error i get with that code as well:
Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in /home/ttoomey/ydnt.com/messageTest.php on line 13
fariquzeli
Forum Contributor
Posts: 144
Joined: Mon Jun 24, 2002 9:16 am
Location: Chicago
Contact:

Post by fariquzeli »

nm, figured it out, thanks guys.
Post Reply