Hi there,
I'm looking to display, say, only the latest 7 news items on my PHP page. The code looks like this at the moment:
<?
$host="***";
$username="***";
$password="***";
$database="***";
mysql_connect($host,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM news order by `date` DESC";
$result=mysql_query($query);
$num=mysql_numrows($result);
if ($num == 0) {
mysql_close();
echo "<i>No news has been posted.</i>";
} else {
mysql_close();
$i=0;
while ($i < $num) {
$title=mysql_result($result,$i,"title");
$date = date('j F Y', strtotime(mysql_result($result,$i,"date")));
$post=mysql_result($result,$i,"post");
$title = strtoupper($title);
$date = strtoupper($date);
echo "<font size=2><b>$date</b> - <i>$title</i></font><br>$post<br><br>";
$i++;
}
}
}
?>
How would I display only the 7 latest results, and how would I display the text "News Archive" if there are more than 7 items?
Thanks!