Displaying set number of results from MySQL
Posted: Sun Dec 01, 2002 12:28 pm
I have a news program in which I want to only display the 10 most recent news posts on the database.
How do I do that?
Thanks
How do I do that?
Thanks
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
$startVal = 0;
$perPage = 10;
$sql = 'SELECT * FROM posts ORDER BY dtDateTime DESC LIMIT '.$startVal.','.$perPage;
...
<a href="ShowPosts.php?startVal=<?php echo $startVal+1; ?>&perPage=<?php echo $perPage; ?>">Next Ten</a>Code: Select all
<?php
mysql_connect($DBhost,$DBuser,$DBpass) or
die("Unable to connect to database");
@mysql_select_db("$DBname") or die("Unable to select database");
$sqlquery = "SELECT * From posts order by 'post_id' DESC";
$result=mysql_query($sqlquery);
$num=mysql_num_rows($result);
$i=0;
while ($i < 5) {
$post_id=mysql_result($result,$i,'post_id');
$post=mysql_result($result,$i,'post');
++$i; }
?>