Jump to content


pagination help


2 replies to this topic

#1 thepoor666

    Young Padawan

  • Members
  • Pip
  • 3 posts

Posted 01 April 2008 - 07:32 PM

I don't think it's the mysql query. Anyone have any ideas? The codebox isn't letting me add the code for some reason, so I'm unable to display what I have. I used the same code, just added a table to display the data. I like to do this outside of php tags, and insert them where needed. Could that be the problem?

#2 dEcade

    P2L Staff

  • P2L Staff
  • PipPipPipPip
  • 1,850 posts
  • Gender:Male
  • Location:Saskatoon, Saskatchewan
  • Interests:Guitar, Programming, Storm Chasing, Games (Designing and playing), Hockey, Photography

Posted 01 April 2008 - 09:49 PM

Post your code, It will be easier to help you then. Just type [code ][/code ] (No space between the "e" and "]")

Should work

dEcade

#3 thepoor666

    Young Padawan

  • Members
  • Pip
  • 3 posts

Posted 02 April 2008 - 06:34 AM

Here it is. I don't know why it wasn't working before. Oh, well.

 <font color="#FFFFFF"><?php
			 if($_GET['page'])
	 {
		 $page = $_GET['page'];
 
	 }else{
		 $page = 1;
	 }
 $max = 25;
 $cur = (($page * $max) - $max);
 
  
 mysql_select_db("products", $con);
 
 $getdata = mysql_query("SELECT * FROM prods LIMIT $cur, $max") or die(mysql_error());
 
 $data = mysql_fetch_array($getdata);
 $counttotal = mysql_query("SELECT * FROM prods") or die(mysql_error());		
 $counttotal = mysql_num_rows($counttotal);
 $total_pages = ceil($counttotal / $max); 
 ?></font>
 <table width="605" height="186" border="0" cellpadding="0" cellspacing="0">
   <tr>
	 <td width="151" height="25" bgcolor="#666666"><font face="verdana" size="1" color="white"> &nbsp;&nbsp;<b>Product</b> </font> </td>
	 <td width="101" height="25" bgcolor="#666666"><font face="verdana" size="1" color="white"> <b>Price</b> </font> </td>
	 <td width="205" height="25" bgcolor="#666666"><font face="verdana" size="1" color="white"> <b>Description</b> </font> </td>
	 <td width="131" height="25" bgcolor="#666666"><font face="verdana" size="1" color="white"> <b>Add</b> </font> </td>
   </tr>
   <?php
			 {
			 ?>
   <tr>
	 <td width="151" height="25" bgcolor="#647977"><font face="verdana" size="1" color="#ffffff">
	   <?php
							 echo $data["itemName"]; ?>
	   
 
	   <img src="<?php echo $data['path'];?>" width="125" height="125" /> </font> </td>
	 <td width="101" height="25" bgcolor="#647977"><font face="verdana" size="1" color="#FFFFFF"> <?php echo $data["itemPrice"]; ?> </font> </td>
	 <td width="205" height="25" bgcolor="#647977"><font face="verdana" size="1" color="#FFFFFF"> <?php echo $data["itemDesc"]; ?> </font> </td>
	 <td width="131" height="25" bgcolor="#647977"><a href="cart.php?action=add_item&id=<?php echo $data["itemId"]; ?>&qty=1"><font color="#FFFFFF">Add Item</font></a> </td>
   </tr>
   <?php
			 }
		 ?>
   <tr>
	 <td colspan="3"><font face="verdana" size="1" color="#FFFFFF"> <a href="cart.php"><font color="#FFFFFF">Your Shopping Cart &gt;&gt;</font></a> </font> </td>
	 <td><?php
				 if($page > 1){
				 $prev = ($page - 1);
				 echo '<a href="?page=' . $prev . '"><font color="#FFFFFF">« Previous</font></a>';
				 }
  
 for($i = 1; $i <= $total_pages; $i++)
				 {
					 if($page == $i)
						 {
							 echo'<b>' . $i .'</b> ';
 
								 } else {
 
							 echo '<a href="?page=' . $i . '"><font color="#FFFFFF">' . $i . '</font></a> ';
						 }
				 }
  
 if($page < $total_pages){
 
					 $next = ($page + 1);
 
				 echo '<a href="?page=' . $next . '"><font color="#FFFFFF">Next »</font></a>';
					 } 
 ?></td>
   </tr>
 </table>






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users