[php] pagination script doesn't works
Posted: Mon Oct 31, 2005 1:35 am
Hi,
i would like to write a script that display all my database records (10 records per page into 2 columns: so 5 records per columns); i would like also to paginate all the page that i'll get by this way: 1, 2, 3, .... (1, 2, 3, ... are hypertext numbers; that means that if i click on "1", i'll go on the first page; if i click on "2" i'll go on the second page etc.)
My code doesn't display any record: only the title of the page with the hypertext numbers are displayed. There are no php errors; the fields name of my database table are rights. I think that the problem comes from my "while" and my "for" loops. Please can you help me to fix my code? Thanks.
i would like to write a script that display all my database records (10 records per page into 2 columns: so 5 records per columns); i would like also to paginate all the page that i'll get by this way: 1, 2, 3, .... (1, 2, 3, ... are hypertext numbers; that means that if i click on "1", i'll go on the first page; if i click on "2" i'll go on the second page etc.)
My code doesn't display any record: only the title of the page with the hypertext numbers are displayed. There are no php errors; the fields name of my database table are rights. I think that the problem comes from my "while" and my "for" loops. Please can you help me to fix my code? Thanks.
Code: Select all
<!doctype html public "-//W3C//DTD HTML 4.0 //EN">
<html>
<head>
<title>Title here!</title>
</head>
<body>
<table>
<tr>
<td colspan="2"><h2><center>Actualités</center></h2>
</td>
</tr>
<tr>
<td>
<?php
include("connexion.php");
$requete=mysql_query("select * from articles order by date desc"); //query
$nombreLignes=mysql_num_rows($requete); //number of database records
$nombreArticlePage=10; //number of article per columns
$nombrePg=ceil($nombreLignes/$nombreArticlePage); //number of pages to be display
$numPgUrl=@$_GET["num"]; //number of page in the url
$numPgCour=0;
$col1=0; //first columns of html table
$col2=0; //second columns of html table
while($numPgCour < $numPgUrl)
{
for($i = 1; $i<=$nombreArticlePage/2; $i++)
{
mysql_fetch_array($requete);
}
$numPgCour++;
}
for($i = 1; $i<=$nombreArticlePage/2; $i++)
{
if ($col1=mysql_fetch_array($requete) == 0) break;
if ($col2=mysql_fetch_array($requete) == 0) break;
echo "<tr><td><b>" .$col1['titre']. "</b></td><td><b>".$col2['titre']."</b></td></tr>
<tr><td>" .$col1['resume']. "</td><td>" .$col2['resume']. "</td></tr>";
}
?>Page<?
for($i = 1; $i<=$nombrePg; $i++)
{
if($numPgUrl == $i)
{
echo $i;
}
else
{ ?>
<a href="?num=<? echo $i ?>"
> <? echo $i; ?> </a>
<? }
}
?>
</table>
</body>
</html>