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 ?> Quote Link to comment Share on other sites More sharing options...
revraz Posted March 10, 2008 Share Posted March 10, 2008 Use LIMIT 3 in your query. Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.