Forum Moderators: coopster

Message Too Old, No Replies

pagination code help please.

         

undream2

2:53 am on Jun 18, 2009 (gmt 0)

10+ Year Member



whats wrong with the code below.. everything is there except the database info..

The code outputs the pictures/data, and the right amount of page numbers.. But, when you click on a page number.. The data doesn't change.. The output of the first page stays the same.. and etc..

I don't need anything fancy.. Just a simple pagination, to output 1000's of pictures from a datafeed. So I can save them without waiting too long for uploads and etc..

so, whats wrong with the code, for the output data to not update. When a page number is clicked..

Thanks A Bunch for any help..

$limit = 20; //number of images per page
$query_count = "SELECT * FROM $usertable";
$result_count = mysql_query($query_count);
$totalrows = mysql_num_rows($result_count);

if(empty($page)){
$page = 1;
}

$limitvalue = $page * $limit - ($limit);

$query = "SELECT * FROM $usertable LIMIT $limitvalue, $limit";
$result = mysql_query($query) or die("Error: " .
mysql_error());
if(mysql_num_rows($result) == 0){
echo("Nothing to Display!");
}

if($result) {
while($row = mysql_fetch_array($result)){
$image = $row["image"];

echo "<img src=$image>";

}
}

echo "<br>";

if($page != 1){
$pageprev = $page -1;

echo("<a class='menu' href='$PHP_SELF?page=$pageprev'> << </a>&nbsp;");
}
else{
echo("&nbsp;");
}

$numofpages = $totalrows / $limit;

for($i = 1; $i <= $numofpages; $i++){
if($i == $page){
echo("[" .$i."]&nbsp;");
}else{
echo("<a class='menu' href='$PHP_SELF?page=$i'>$i</a>&nbsp;");
}
}


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

if(($totalrows - ($limit * $page)) >= 0){
$pagenext = $page +1;

echo("<a class='menu' href='$PHP_SELF?page=$pagenext'> >> </a>");
}else{
echo("&nbsp;");
}

mysql_free_result($result);

?>

dreamcatcher

6:26 am on Jun 18, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If your server has register_globals OFF, using $page won`t work. You must access the variable via the superglobal $_GET.

Change this:

if(empty($page)){
$page = 1;
}

to this:

$page = (isset($_GET['page']) ? $_GET['page'] : '1');

If this is a public page, further filtering on the $page var is required. Always check your variables to see whats coming in.

dc

undream2

3:13 pm on Jun 18, 2009 (gmt 0)

10+ Year Member



you're a genius my friend..
it worked just as you said..

undream2

3:14 pm on Jun 18, 2009 (gmt 0)

10+ Year Member



oh yeah,, thank you so much..

dreamcatcher

6:26 pm on Jun 18, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You`re very welcome. :)

dc