Show 20 results a page

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
arrowhead
Forum Newbie
Posts: 4
Joined: Wed Mar 25, 2009 5:02 pm

Show 20 results a page

Post by arrowhead »

PHP code: this is getting all the data from news table.

Code: Select all

 
<?php
 
mysql_select_db($database_TL, $News);
$query_Recordset1 = "SELECT *,DATE_format(date, '%d.%m.%Y ') as newdate FROM `news` order by date desc";
 
$Recordset1 = mysql_query($query_Recordset1, $News) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
 
?>
 
and this is where i post results:

Code: Select all

 
  <?php
  $idx = 1;
  do {?>
  
<p><strong><?php echo $row_Recordset1['newdate']; ?> - <?php echo $row_Recordset1['writer']; ?></strong>
<br /><a href="article.php?id=<?php echo $row_Recordset1['id']; ?>"><?php echo $row_Recordset1['baslik']; ?></a></p>
 
<?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?> 
 
since i have over 100 data in that table, they all show up in one page.

I hope to get help to show 20 results in a page with using these codes.

Thanks a lot.
Last edited by Benjamin on Thu May 07, 2009 11:47 am, edited 1 time in total.
Reason: Changed code type from text to php.
User avatar
Gabriel
Forum Commoner
Posts: 41
Joined: Wed May 06, 2009 8:12 pm
Location: Las Vegas

Re: Show 20 results a page

Post by Gabriel »

What you want is called pagination.
ldougherty
Forum Contributor
Posts: 103
Joined: Sun May 03, 2009 11:39 am

Re: Show 20 results a page

Post by ldougherty »

Whenever I've needed to output a list of results over several pages I'll store the results from the query into an array and then return x amount of items from the array on each page.

Hope that points you in the right direction.
Post Reply