stublackett Posted March 10, 2008 Share Posted March 10, 2008 Hi, I've got a news system implemented which posts to index.php But due to size constraints and usability rules I've decided against a scrollbar So what I'd like to do is limit the amount of items pulled from a Database to 3 at a max, But those 3 being the latest 3 news items added to the database Any ideas on how I can do this!? Heres my code which pulls the news item(s) from the database, Obviously with screen sizes of my page it becomes an issue if there are more than 3 news items posted to the Database, So would like to limit the News posted to just 3, 3 items from the DB then being output onto the page Any help is much appreciated! CODE : <?php #news-index.php By Stuart Blackett include("dbconnect.php"); $result = mysql_query("SELECT * FROM $db_table ORDER BY dtime DESC",$connect); //lets make a loop and get all news from the database while($myrow = mysql_fetch_assoc($result)) {//begin of loop //now print the results: echo "<b>Title: "; echo $myrow['title']; echo "</b><br><br>Posted: "; echo $myrow['dtime']; echo "<br> <br>"; echo $myrow['text1']; echo "<br>"; // Now print the options to (Read,Edit & Delete the news) echo "<br><a href=\"read_more.php?newsid=$myrow[newsid]\">Read Further</a> || <a href=\"add_news.php\">Add News</a> || <a href=\"edit_news.php?newsid=$myrow[newsid]\">Edit</a> || <a href=\"delete_news.php?newsid=$myrow[newsid]\">Delete</a><br><br>"; }//end of loop ?> Link to comment https://forums.phpfreaks.com/topic/95470-limiting-amount-of-data-pulled-from-an-mysql-database/ Share on other sites More sharing options...
revraz Posted March 10, 2008 Share Posted March 10, 2008 Use LIMIT 3 in your query. Link to comment https://forums.phpfreaks.com/topic/95470-limiting-amount-of-data-pulled-from-an-mysql-database/#findComment-488700 Share on other sites More sharing options...
stublackett Posted March 10, 2008 Author Share Posted March 10, 2008 Jackpot! I thought it might have been changing something in PHP rather than the SQL thats done the trick Many thanks Link to comment https://forums.phpfreaks.com/topic/95470-limiting-amount-of-data-pulled-from-an-mysql-database/#findComment-488711 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.