error trying to print last 3 db entries

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

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

error trying to print last 3 db entries

Post by fariquzeli »

here is my code:

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);
?>

<?php
$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 );
?>
I now the formatting is wrong on that echo and it's real ugly, just wondering if anyone had a better way to format that line, here's the error i get:
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!
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Please don't cross-post. If you're going to move your topic to another forum note that in the original post so you don't end up with two active threads about the same thing.

Oh and if you solve your problem tell people how you did it, it might help someone else along the line...

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

Post by fariquzeli »

the reason for the cross post was that i changed the post almost entirely and decided it was more suited for the db forum.

here's the final code and how i got this solved:

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 LIMIT 3";
$news = mysql_query($query_news, $ydntNews) or die(mysql_error());
$row_news = mysql_fetch_assoc($news);

$headline = $row_news&#1111;'headline'];
$id = $row_news&#1111;'id'];

echo("messages&#1111;0]="<font face='verdana' color='#ffffff' size='1'>$headline</b><br> :<a href='http://www.yiinc.com/news.php?id=$id'><font color='#cccccc'>Full Story</a></font>"\n");

$i = 1;

while ($row_news = mysql_fetch_array($news)) &#123;
$headline = $row_news&#1111;'headline'];
$id = $row_news&#1111;'id'];

echo("messages&#1111;$i]="<font face='verdana' color='#ffffff' size='1'>$headline</b><br> :<a href='http://www.yiinc.com/news.php?id=$id'><font color='#cccccc'>Full Story</a></font>"\n");
$i++;
&#125;
?>
That retrieves the last 3 results using a mysql fetch array and repeats it twice.
Post Reply