clown[NOR] Posted April 15, 2007 Share Posted April 15, 2007 is there an easy way to do this or do I have to just loop it like i do now? this is what i'm using now... <?php ## Get the last 5 news... function freshNews() { global $dbHost, $dbUser, $dbPass, $dbName; if (!mysql_connect($dbHost, $dbUser, $dbPass)) { die("Unable to connect to DB"); } if (!mysql_select_db($dbName)) { die("Unable to select DB"); } $query = "SELECT * FROM news"; $result = mysql_query($query); if (!$result) { die("Could not run query from DB"); } $dbNumRows = mysql_num_rows($result); if ($dbNumRows > 0) { $i = 1; while ($dbNumRows > 0) { if ($i <= 5) { $query = "SELECT * FROM news WHERE nid = '".$dbNumRows."'"; $result = mysql_query($query); $newsItem = mysql_fetch_assoc($result); if (strlen($newsItem['title']) > 30) { echo '<a href="?view=news&id='.$newsItem['nid'].'">'.substr($newsItem['title'], 0, 30)."...</a><br>"; } else { echo '<a href="?view=news&id='.$newsItem['nid'].'">'.$newsItem['title']."</a><br>"; } $dbNumRows = $dbNumRows - 1; $i++; } else { break; } } } else { echo "No news found."; } } ?> Link to comment https://forums.phpfreaks.com/topic/47129-solved-mysql-read-from-the-bottom-to-the-top-of-the-table/ Share on other sites More sharing options...
ignace Posted April 15, 2007 Share Posted April 15, 2007 why don't u just use: SELECT * FROM `news` ORDER BY `news_publish_date` DESC LIMIT 5 Link to comment https://forums.phpfreaks.com/topic/47129-solved-mysql-read-from-the-bottom-to-the-top-of-the-table/#findComment-229798 Share on other sites More sharing options...
clown[NOR] Posted April 15, 2007 Author Share Posted April 15, 2007 oh my god... i feel really stupid right now... Link to comment https://forums.phpfreaks.com/topic/47129-solved-mysql-read-from-the-bottom-to-the-top-of-the-table/#findComment-229800 Share on other sites More sharing options...
ignace Posted April 15, 2007 Share Posted April 15, 2007 i always do to Link to comment https://forums.phpfreaks.com/topic/47129-solved-mysql-read-from-the-bottom-to-the-top-of-the-table/#findComment-229801 Share on other sites More sharing options...
clown[NOR] Posted April 15, 2007 Author Share Posted April 15, 2007 well... now I got this message: Could not run query from DB EDIT: nevermind... my stupidity striked again... wrote ORBER instead of ORDER..haha Link to comment https://forums.phpfreaks.com/topic/47129-solved-mysql-read-from-the-bottom-to-the-top-of-the-table/#findComment-229802 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.