mrgrim333 Posted September 28, 2009 Share Posted September 28, 2009 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 Link to comment https://forums.phpfreaks.com/topic/175835-news-in-decending-order/ Share on other sites More sharing options...
Alex Posted September 28, 2009 Share Posted September 28, 2009 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 https://forums.phpfreaks.com/topic/175835-news-in-decending-order/#findComment-926541 Share on other sites More sharing options...
mrgrim333 Posted September 28, 2009 Author Share Posted September 28, 2009 ... I didn't know the query could handle that! You sir are dead sexy... Have my babies? Link to comment https://forums.phpfreaks.com/topic/175835-news-in-decending-order/#findComment-926546 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.