Page 1 of 1

Show 20 results a page

Posted: Thu May 07, 2009 10:43 am
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.

Re: Show 20 results a page

Posted: Thu May 07, 2009 2:31 pm
by Gabriel
What you want is called pagination.

Re: Show 20 results a page

Posted: Thu May 07, 2009 7:05 pm
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.