0

I am working on a pagination.From the index page it goes with a variable .For an example:

viewproduct_by_category.php?categoryid=1

the value 1 comes from database.So the error is ,first time the page shows up all the images that has the categoryid =1 but second time when ever I press next page it shows nothing but the pagination values like <<1.2.3..>>

I figured out the problem but I have no idea how to fix it cause each time the page loads the same page .For the first time

$_SESSION['productcat']=$_REQUEST['categoryid'];

Gets the value but when it reloads the same poage it gets nothing so How can I preserve the value.


I will be very happy if some one help me with this.

Thanks

4
Contributors
4
Replies
5
Views
5 Years
Discussion Span
Last Post by mlhazan
0

You are fetching images based on categoryid passed in link viewproduct_by_category.php?categoryid=1.
So when you click next link url should also have categoryid i.e. viewproduct_by_category.php?categoryid=1&page=2.
Check in your coding whether you are getting it or not.

0

i can help you if you let me know your email i can send you the code and files of pagination which i made and then you can change it your ways

0

Can the thread starter please search for 'pagination' within the PHP forum? I've contributed to about 100 of these threads. There is so much info there, just look. Pointless reinventing the wheel every time.

0

You are fetching images based on categoryid passed in link viewproduct_by_category.php?categoryid=1.
So when you click next link url should also have categoryid i.e. viewproduct_by_category.php?categoryid=1&page=2.
Check in your coding whether you are getting it or not.

Thanks for your reply.My codes are fine when I statically put a value on categoryid i.e 1 or 2...but when I send this value from another page and grab it using request it works only for the first page and second page is empty.I know it is not a good idea to put the whole code but for convenience I am posting it here:

$productcat=$_REQUEST['categoryid'];
$str=mysql_query("select *
from product 
where product.productid in
(select productcategory.productid
from productcategory where productcategory.productcat='" . $productcat."') and special='No'
")or die(mysql_error());
	$totalrecord=mysql_num_rows($str);
	$count=0;	
	
	$pagesize=3;
	$noofpages=$totalrecord/$pagesize;
	if (!isset($_REQUEST['start']))
	$start=0;
	else
	$start=$_REQUEST['start'];
	$count=$start;
	$strrec="select *
                 from product 
                 where product.productid in
                (select productcategory.productid
                 from productcategory where productcategory.productcat='" .                                 $productcat."') and special='No'
order by productid DESC limit ".$start.",".$pagesize;

	$k=0;	
	$res1=mysql_query($strrec) or die("cannot select product");

	while ($row=mysql_fetch_array($res1))   {
	$k++;
	$count++;

?>


      
      <td width="200" height="18" class=algray>
	  <a href="../admin/product/viewproduct.php?productid=<? echo $row["productid"] ?>"><font class=tablacks><b><? echo $row["product"]; ?></b></font></a>
      <img src="../admin/product/photo/<? echo $row["photo"] ?>" width="100%" height="160"></font><br></td>

<?
if($k%3==0){
	?>
	</tr>
	
<?	}
}

?>


</table>
</div>

<!------------------------------------------------------------------------------------------------------------>


     
<?
if($start<>0) 
{
$prev=$start-$pagesize;
echo "<a href='./viewproduct_by_category.php?start=".$prev."'><font class=torange><b><< Prev</b></a>&nbsp;&nbsp;";
}
?>


<font class=tablackb>Page</font> <font class=tablack><?
for ($i=0;$i<$noofpages;$i++)
{
	$pageno=$i+1;
	$j=($pagesize*$pageno)-$pagesize;

	if ($start==0 && $i==0)
	{
		echo "<font class=tablackb>". $pageno."</b></font> ";
	}
	else
	{
		if($start == ($pagesize*($pageno))-$pagesize)
		{
			echo "<font class=tablack>". $pageno."</font> ";
		}
		else
		{
			echo "<a href='./viewproduct_by_category.php?start=".$j."'><font class=tablackb>". $pageno. "<font></a> ";
 		}
	}
}
?></font>

<?
if($start+$pagesize<$totalrecord)
{
$next=$start+$pagesize;
	echo "&nbsp;&nbsp;<a href='viewproduct_by_category.php?start=".$next."'><font class=torange>Next>> </a>";
}
?>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.