Forum Moderators: coopster
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> ");
}
else{
echo(" ");
}
$numofpages = $totalrows / $limit;
for($i = 1; $i <= $numofpages; $i++){
if($i == $page){
echo("[" .$i."] ");
}else{
echo("<a class='menu' href='$PHP_SELF?page=$i'>$i</a> ");
}
}
if(($totalrows % $limit) != 0){
if($i == $page){
echo("[" .$i."] ");
}else{
echo("<a class='menu' href='$PHP_SELF?page=$i'>$i</a> ");
}
}
if(($totalrows - ($limit * $page)) >= 0){
$pagenext = $page +1;
echo("<a class='menu' href='$PHP_SELF?page=$pagenext'> >> </a>");
}else{
echo(" ");
}
mysql_free_result($result);
?>
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