Jump to content

Archived

This topic is now archived and is closed to further replies.

piet bierbuik

pagination

Recommended Posts

hi,

i've created a pagination script and it works... half, not like i want.
http://84.244.181.93/~vandenberg/onlinetilburg/pagenation.php
1. the PREV button doesn't work.
2. if i press like same number 10, the numbering say its on page 11.

can someone help me alternate this file.

oops, sorry

[code]
<?php
include ("connect.php");

$limit = 5;   
$query_count = "SELECT * FROM uitgaan";   
    // count(*) is better for large databases (thanks Greg!)
$result_count  = mysql_query($query_count);       
$totalrows  = mysql_num_rows($result_count);   
$page = $_GET['page'];

if(empty($page))

        $page = 1;   
    }
$limitvalue = $page * $limit - ($limit);
echo "<br>";
echo "-----------------------------------------";
echo "<br>";
echo '$page=', $page;
echo "<br>";
echo '$limitvalue=',$limitvalue;
echo "<br>";
echo "-----------------------------------------";
echo "<br>";
echo "<br>";
 
$query  = "SELECT * FROM uitgaan LIMIT $limitvalue, $limit";       
$result = mysql_query($query) or die("Error: " . mysql_error()); 

if(mysql_num_rows($result) == 0)
{
        echo("Nothing to Display!");
    }

while ($rij = mysql_fetch_array ($result))
{
echo $rij['naam'],"</BR>";
}

if($page != 1)

$pageprev = $page++;
echo("<a href=\"$_SERVER[PHP_SELF]?page=$pageprev\">PREV".$limit."</a> ");   
}
else
{
echo("PREV".$limit." "); 
}

$numofpages = $totalrows / $limit; 

for($i = 1; $i <= $numofpages; $i++)
{
if($i == $page)
{
echo($i." ");
}
else
{
            echo("<a href=\"$_SERVER[PHP_SELF]?page=$i\">$i</a> ");
        }
       
}


if(($totalrows % $limit) != 0)
{     
if($i == $page)
{
echo($i." ");
}
else
{
echo("<a href=\"$_SERVER[PHP_SELF]?page=$i\">$i</a> ");
}
}

if(($totalrows - ($limit * $page)) > 0)
{
$pagenext  = $page--;
echo("<a href=\"$_SERVER[PHP_SELF]?page=$pagenext\">NEXT".$limit."</a>");
}

else
{
echo("NEXT".$limit);
}

?>
[/code]

Share this post


Link to post
Share on other sites
Post your code so we can see what's going on

EDIT: beat me to it :)
Ray

Share this post


Link to post
Share on other sites

change $pageprev = $page++; to $pageprev = $page-1;

and $pagenext  = $page--; to $pagenext  = $page+1;

Share this post


Link to post
Share on other sites
yes it worked thx you sasa.
i thought $i++ is the same as $i+1, but now it works so im happy.

here is the full code:

[code]<?php
include ("connect.php");

$limit = 5;   
$query_count = "SELECT * FROM table";
$result_count  = mysql_query($query_count);       
$totalrows  = mysql_num_rows($result_count);   
$page = $_GET['page'];

if(empty($page))

        $page = 1;   
    }
$limitvalue = $page * $limit - ($limit); 
$query  = "SELECT * FROM table LIMIT $limitvalue, $limit";       
$result = mysql_query($query) or die("Error: " . mysql_error()); 

if(mysql_num_rows($result) == 0)
{
        echo("Nothing to Display!");
    }

while ($rij = mysql_fetch_array ($result))
{
echo $rij['naam'],"</BR>";
}

if($page != 1)

$pageprev = $page-1;
echo("<a href=\"$_SERVER[PHP_SELF]?page=$pageprev\">PREV".$limit."</a> ");   
}
else
{
echo("PREV".$limit." "); 
}

$numofpages = $totalrows / $limit; 

for($i = 1; $i <= $numofpages; $i++)
{
if($i == $page)
{
echo($i." ");
}
else
{
            echo("<a href=\"$_SERVER[PHP_SELF]?page=$i\">$i</a> ");
        }
       
}


if(($totalrows % $limit) != 0)
{     
if($i == $page)
{
echo($i." ");
}
else
{
echo("<a href=\"$_SERVER[PHP_SELF]?page=$i\">$i</a> ");
}
}

if(($totalrows - ($limit * $page)) > 0)
{
$pagenext = $page+1;
echo("<a href=\"$_SERVER[PHP_SELF]?page=$pagenext\">NEXT".$limit."</a>");
}

else
{
echo("NEXT".$limit);
}

?>

[/code]

Share this post


Link to post
Share on other sites
[quote author=piet bierbuik link=topic=111683.msg452994#msg452994 date=1161075883]
yes it worked thx you sasa.
i thought $i++ is the same as $i+1, but now it works so im happy.
[/quote]

Actually what you want (I know this is correct in C++) is ++$i
[code]
<?php

$i = 0;
$tmp = $i++;
echo $tmp ."<br />";

$tmp = ++$i;
echo $tmp ."<br />";

?>
[/code]

This will produce:
[code]
0
2
[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.