Limit MySQL records show blank per page?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Red Blaze
Forum Commoner
Posts: 40
Joined: Mon Mar 27, 2006 3:45 pm

Limit MySQL records show blank per page?

Post by Red Blaze »

Hi again. I ran into a tutorial that helped me out in one piece, but left me in the dark once I was done. I'm using this piece of code to show 5 records per page.

Code: Select all

$page_name="cart.php"; // If you use this code with a different page ( or file ) name then change this 
if(!isset($start)) { // This variable is set to zero for the first page
$start = 0;
}
$eu = ($start - 0);
$limit5 = 5; // No of records to be shown per page.
$this = $eu + $limit5;
$back = $eu - $limit5;
$next = $eu + $limit5;

$query5=" SELECT * FROM items WHERE userid = $userid AND albumid = $session_album AND original = '1' ORDER BY itemid ASC";
$result5=mysql_query($query5);
echo mysql_error();
$nume=mysql_num_rows($result5);



<?php 
echo "<table align = 'center' width='50%'><tr><td align='left' width='30%'>";
if($back >=0) {
print "<a href='$page_name?start=$back'><font face='Verdana' size='2'>PREV</font></a>";
}
echo "</td><td align=center width='30%'>";
$i=0;
$l=1;
for($i=0;$i < $nume;$i=$i+$limit5){
if($i <> $eu){
echo "<a href='$page_name?start=$i'><font face='Verdana' size='2'>$l</font></a>";
}
else { echo "<font face='Verdana' size='4' color=red>$l</font>";} /// Current page is not displayed as link and given font color red
$l=$l+1;
echo "</td><td align='center' width='30%'>";
}
if($this < $nume) {
print "<a href='$page_name?start=$next'><font face='Verdana' size='2'>NEXT</font></a>";}
echo "</td></tr></table>";
		  ?>
The top part is over the header, the bottom part is in the body. Now, it all works fine. But in my page, the users can delete rows (the photos they don't want). Now, when they're in the 2nd page and delete all the photos in the 2nd page, they get nothing. How can I throw the user to the previous page? I don't really know how to do that. Thank you!
jimbanks
Forum Newbie
Posts: 2
Joined: Wed Apr 05, 2006 11:28 am

Post by jimbanks »

Just FYI... if you just need 5 rows... try....

select * from table1 LIMIT 1,5
Post Reply