Creating a pagination function in PHP that exist in other class that generate the HTML
I need help creating a pagination function in PHP. I have created one that works great if it exist in the index page. I tried to put it in an PHP class it didn't work. Any help please. This is the code:
function pag开发者_C百科ing($eu,$limit,$back,$next,$nume,$t1)
{
$l=1;
$i=0;
echo $eu; //$
echo $limit; // maximum record per page
//echo $back;
echo $next; //next page
echo $nume; // number of rows
if($back >=0)
{
$a = "<a _href='index?start=$back'>PREV</a>";
}
else
{
$a ="";
}
for($i=0;$i < $nume;$i=$i+$limit)
{
if($i <> $eu)
{
$b = " <='index?start=$i'>$l</a>";
$c = "";
}
else
{
$b = "";
$c =$l;
$l=$l+1;
}
}
if($t1 < $nume)
{
$e = "<='index.php?start=$next'>NEXT</a>";
}
$pg = "
<table>
<tr>
<td>$a</td>
<td>$b $c</td>
<td>$e</td>
</tr>
</table>
";
return $pg;
}
Most likely this is where you're messing up:
for($i=0;$i < $nume;$i=$i+$limit) {
if ($i <> $eu) {
$b = " <='index?start=$i'>$l</a>"; // <--- here
$c = "";
} else {
$b = ""; // <<--- here
$c =$l;
$l=$l+1;
}
}
You're overwriting the $b
value on each loop iteration, instead of appending the "current" page HTML. Most likely you'd want something like this instead:
$b .= " <='index?start=$i'>$l</a>";
^--- concatenation operator
which is the same as doing:
$b = $b . " <='index?start=$i'>$l</a>";
精彩评论