Limiting news on a news section

Hello,
I was developing a website that uses PHP to display news out of a mysql database. The code to display the news works fine but i wanted to limit the amount of news it shows.
Here is the code -

<?php $dbhost = 'mysql'; $dbusername = 'awmotorsports'; $dbpasswd = 'muffin'; $database_name = 'awmotorsports'; $connection = mysql_pconnect("$dbhost","$dbusername","$dbpasswd") or die ("Couldn't connect to server."); $db = mysql_select_db("$database_name", $connection) or die("Couldn't select database."); $getnews = mysql_query("SELECT * FROM news ORDER BY id DESC"); while ($row = mysql_fetch_assoc($getnews)) { $id = $row['id']; $title = $row['title']; $body = $row['body']; $date = $row['date']; echo"
$title
posted on $date

"; echo nl2br($body); echo "


"; } ?>
                 i was wondering how i could limit the while loop to only 3 repititions of the info below it

If you want to display just 3 news records, you can add limit parameter in your sql query:
[php]$getnews = mysql_query(“SELECT * FROM news ORDER BY id DESC LIMIT 3”);[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service