Jump to content

Pagination help please


Dave2711

Recommended Posts

Hi guys, ive been using a few guides to do pagination.. most of which I couldn't get to work atall.. and now ive got to one which works, except when I change pages it loads the same images on the page as it did before. Just wondering if anyone can point me in the right direction about fixing this?

 

<?php include('includes/header.php');
include('includes/sq-config.php');
?>

<img src="images/images.jpg">
<br><br>
<table width="95%" align="center" cellpadding="5" background="images/bg.gif">
<tr>
	<td>
<?

if (!(isset($pagenum)))
{
$pagenum = 1;
}

$data = mysql_query("SELECT * FROM img") or die(mysql_error());
$rows = mysql_num_rows($data);


$page_rows = 10;


$last = ceil($rows/$page_rows);


if ($pagenum < 1)
{
$pagenum = 1;
}
elseif ($pagenum > $last)
{
$pagenum = $last;
}


$max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows; 

$data_p = mysql_query("SELECT * FROM img $max") or die(mysql_error());

while($info = mysql_fetch_array( $data_p ))
{
echo "<tr><td><a href=pic.php?id=" . $info['id'] . ">";
echo "<img width=100 height=100 src=uploads/" . $info['img_dir'] . "></a></td>";
echo "<td padding=2 bgcolor=ffffff><a href=pic.php?id=" . $info['id'] . ">";
echo "<b>" . $info['img_nme'] . "</b></a>";
echo "<br>" . $info['img_dsc'] . "</td></tr>";
}
echo "</td></tr></table>";


echo "Page $pagenum of $last <b>";

if ($pagenum == 1)
{
}
else
{
echo "<td><a href='{$_SERVER['PHP_SELF']}?pagenum=1'>«« First</a> ";
echo " ";
$previous = $pagenum-1;
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous'>« Previous</a>";
}


echo "   ";


if ($pagenum == $last)
{
}
else {
$next = $pagenum+1;
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next'>Next »</a> ";
echo " ";
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last'>Last »»</a> ";
}
?>

<? include('includes/footer.php'); ?> 

Link to comment
https://forums.phpfreaks.com/topic/168129-pagination-help-please/
Share on other sites

Sorrrrrry bad habits lol

 

<?php include('includes/header.php');
include('includes/sq-config.php');
?>

<img src="images/images.jpg">
<br><br>
<table width="95%" align="center" cellpadding="5" background="images/bg.gif">
<tr>
	<td>
<?php

if (!(isset($pagenum)))
{
$pagenum = 1;
}

$data = mysql_query("SELECT * FROM img") or die(mysql_error());
$rows = mysql_num_rows($data);


$page_rows = 10;


$last = ceil($rows/$page_rows);


if ($pagenum < 1)
{
$pagenum = 1;
}
elseif ($pagenum > $last)
{
$pagenum = $last;
}


$max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows; 

$data_p = mysql_query("SELECT * FROM img $max") or die(mysql_error());

while($info = mysql_fetch_array( $data_p ))
{
echo "<tr><td><a href=pic.php?id=" . $info['id'] . ">";
echo "<img width=100 height=100 src=uploads/" . $info['img_dir'] . "></a></td>";
echo "<td padding=2 bgcolor=ffffff><a href=pic.php?id=" . $info['id'] . ">";
echo "<b>" . $info['img_nme'] . "</b></a>";
echo "<br>" . $info['img_dsc'] . "</td></tr>";
}
echo "</td></tr></table>";


echo "Page $pagenum of $last <b>";

if ($pagenum == 1)
{
}
else
{
echo "<td><a href='{$_SERVER['PHP_SELF']}?pagenum=1'>«« First</a> ";
echo " ";
$previous = $pagenum-1;
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous'>« Previous</a>";
}


echo "   ";


if ($pagenum == $last)
{
}
else {
$next = $pagenum+1;
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next'>Next »</a> ";
echo " ";
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last'>Last »»</a> ";
}
?>

<?php include('includes/footer.php'); ?> 

 

Hows that? :P

thanks :D

 

try this

 

<?php include('includes/header.php');
include('includes/sq-config.php');
?>

<img src="images/images.jpg">
<br><br>
<table width="95%" align="center" cellpadding="5" background="images/bg.gif">
   <tr>
      <td>
<?php

if(!isset($pagenum)){ $pagenum = 1; }

$data = mysql_query("SELECT * FROM img") or die(mysql_error());
$rows = mysql_num_rows($data);
$page_rows = 10;
$last = ceil($rows/$page_rows);

if ($pagenum < 1){ $pagenum = 1; }
elseif ($pagenum >= $last){ $pagenum = $last; }


$max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows; 

$data_p = mysql_query("SELECT * FROM img $max") or die(mysql_error());
$next = $pagenum+1;
while($info = mysql_fetch_array( $data_p ))
{
echo "<tr><td><a href=pic.php?id=" . $info['id'] . ">";
echo "<img width=100 height=100 src=uploads/" . $info['img_dir'] . "></a></td>";
echo "<td padding=2 bgcolor=ffffff><a href=pic.php?id=" . $info['id'] . ">";
echo "<b>" . $info['img_nme'] . "</b></a>";
echo "<br>" . $info['img_dsc'] . "</td></tr>";
}
echo "</td></tr></table>";


echo "Page $pagenum of $last <b>";

if ($pagenum == 1)
{
}
else
{
echo "<td><a href='{$_SERVER['PHP_SELF']}?pagenum=1'>«« First</a> ";
echo " ";
$previous = $pagenum-1;
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous'>« Previous</a>";
}


echo "   ";


if ($pagenum == $last)
{
}
else {

echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next'>Next »</a> ";
echo " ";
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last'>Last »»</a> ";
}
?>

<?php include('includes/footer.php'); ?> 

No still no luck, it knows how many pages there should be.. but it just seems to fetch the same data, also the links dont change so although its changing the URL adding pagenum=2, its still showing the Next/Last links, I dont understand it haha.. probably something stupid i've missed.

you forgot

 

$_GET['pagenum'];

 

 

its always going to be the same lol cause theres no HTTP GET VAR.

 

try

 

 

<?php include('includes/header.php');
include('includes/sq-config.php');
?>

<img src="images/images.jpg">
<br><br>
<table width="95%" align="center" cellpadding="5" background="images/bg.gif">
   <tr>
      <td>
<?php
$pagenum = $_GET['pagenum'];
if(!isset($pagenum)){ $pagenum = 1; }

$data = mysql_query("SELECT * FROM img") or die(mysql_error());
$rows = mysql_num_rows($data);
$page_rows = 10;
$last = ceil($rows/$page_rows);

if ($pagenum < 1){ $pagenum = 1; }
elseif ($pagenum >= $last){ $pagenum = $last; }


$max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows; 

$data_p = mysql_query("SELECT * FROM img $max") or die(mysql_error());
$next = $pagenum+1;
while($info = mysql_fetch_array( $data_p ))
{
echo "<tr><td><a href=pic.php?id=" . $info['id'] . ">";
echo "<img width=100 height=100 src=uploads/" . $info['img_dir'] . "></a></td>";
echo "<td padding=2 bgcolor=ffffff><a href=pic.php?id=" . $info['id'] . ">";
echo "<b>" . $info['img_nme'] . "</b></a>";
echo "<br>" . $info['img_dsc'] . "</td></tr>";
}
echo "</td></tr></table>";


echo "Page $pagenum of $last <b>";

if ($pagenum == 1)
{
}
else
{
echo "<td><a href='{$_SERVER['PHP_SELF']}?pagenum=1'>«« First</a> ";
echo " ";
$previous = $pagenum-1;
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous'>« Previous</a>";
}


echo "   ";


if ($pagenum == $last)
{
}
else {

echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next'>Next »</a> ";
echo " ";
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last'>Last »»</a> ";
}
?>

<?php include('includes/footer.php'); ?> 

Archived

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

×
×
  • 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.