Jump to content

[SOLVED] Displaying data from table


voxxtelum

Recommended Posts

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.