MySQL Forums
Forum List  »  PHP

Display limited table info.
Posted by: deliverance1957
Date: February 23, 2006 07:58PM

Where to start... Okey, I am trying to set up a front page for announcements.
Right now my issue is that I'm not sure how to list 3 announcements from my table, newest to oldest.

First I tried mysql_fetch_array($sql_result)

which looks like this:
-------------------------------------------------------|
while ($row = mysql_fetch_array($sql_result)) {
$id = $row["ID"];
$date = $row["DATE"];
$title = $row["TITLE"];
$info = $row["INFO"];
$table_data .= "<TR>
<td>$id</td>
<td>$date</td>
<td>$title</td>
<td>$info</td>
</tr>";
}
-------------------------------------------------------|



But, that displays everything in the table not the last 3...
so I came up with this to find my logic incorrect:
-------------------------------------------------------|
$row = mysql_fetch_array($result);
$id = $rec["ID"];
$total = mysql_query(SELECT COUNT(*) FROM announcements);

for ($j=$total; j > $total - 3; $j--) {
...
}
------------------------------------------------------|

Can anyone help clear me up a little, seems like I just keep hitting walls with writers block.



Edited 1 time(s). Last edit at 02/23/2006 08:01PM by deliverance1957.

Options: ReplyQuote


Subject
Written By
Posted
Display limited table info.
February 23, 2006 07:58PM
February 23, 2006 10:43PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.