Jump to content

News in decending order?


mrgrim333

Recommended Posts

So this is what I've got so far.

$getnews = mysql_query("SELECT MAX(id) FROM posts");

if (!$getnews) {
    die('Could not connect: ' . mysql_error());
}

for($i = 0;$i<5;$i++)
{
         $row = mysql_fetch_assoc($getnews);
$id = $row['id'];
$title = $row['title'];
$body = $row['body'];
$date = $row['date'];
$name = $row['name'];

echo "<table width=500>
<tr><td bgcolor=#FFFFFF colspan=2>
<b><center>$title</b></center></td></tr>
<tr><td colspan=2 bgcolor=222222>
<div align=left><font color=#FFFFFF><b> $name</b> posted this $date</font></div>
</td></tr>

<tr><td valign=top align=left width=75><img src=images/seth.jpg><br></td><td align=left valign=top >";

echo nl2br($body);

echo "<BR><BR></td></tr></table>";
}

 

It's not working  :confused:

Link to comment
Share on other sites

Your query is only selecting MAX(id), which won't help you if you're trying to display other information.

 

You should let your query handle the ordering and limiting, you should do something like this:

 

$getnews = mysql_query("SELECT * FROM posts ORDER by `id` DESC LIMIT 5");

if (!$getnews) {
    die('Could not connect: ' . mysql_error());
}

while($row = mysql_fetch_assoc($getnews))
{
     echo "<table width=500>
<tr><td bgcolor=#FFFFFF colspan=2>
<b><center>{$row['title']}</b></center></td></tr>
<tr><td colspan=2 bgcolor=222222>
<div align=left><font color=#FFFFFF><b> {$row['name']}</b> posted this {$row['date']}</font></div>
</td></tr>

<tr><td valign=top align=left width=75><img src=images/seth.jpg><br></td><td align=left valign=top >";

echo nl2br($row['body']);

echo "<BR><BR></td></tr></table>";
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.