Jump to content

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]
Link to comment
https://forums.phpfreaks.com/topic/24125-pagination/
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]
Link to comment
https://forums.phpfreaks.com/topic/24125-pagination/#findComment-109906
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]
Link to comment
https://forums.phpfreaks.com/topic/24125-pagination/#findComment-109909
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.