voxxtelum Posted February 8, 2008 Share Posted February 8, 2008 I have setup an announcements section on my site that retrieves the announcements from a table and displays them. In the table each announcement has an id, title, description, and a link. The code I am using is <?php require("config.php"); // connect to the mysql server $link = mysql_connect($server, $db_user, $db_pass) or die ("Could not connect to mysql because ".mysql_error()); // select the database mysql_select_db($database) or die ("Could not select database because ".mysql_error()); $fetch_announce = mysql_query("select * from announcements"); while ($row = mysql_fetch_array($fetch_announce)) { echo "<a href ='".$row['link']."'><h5>".$row['title']."</h5></a>"; echo "<a>".$row['text']."</a><br><br>"; } ?> It outputs into a div that i want to keep at one height. However, as I add more announcements, it will go beyond the div. My question is that is there a way that when I retrieve the announcements, that it only echos the last 3 announcements in the table? For example if i had 6 rows, I would only want to output rows 4, 5, and 6. Thanks in advance for your time. Link to comment https://forums.phpfreaks.com/topic/90010-solved-displaying-data-from-table/ Share on other sites More sharing options...
awpti Posted February 8, 2008 Share Posted February 8, 2008 Look up LIMIT for mysql and ORDER BY Link to comment https://forums.phpfreaks.com/topic/90010-solved-displaying-data-from-table/#findComment-461530 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.