gfX Posted August 5, 2006 Share Posted August 5, 2006 Okay, So I have a photogallery with pagination. And I set the limit to 3 photos per page. And it has pagination for different pages. So, Say I have 7 Images in the database. I SHOULD have 3 pages, and the third page should only have one image. Well, My problem is: If I had 7 images, It would only make 2 pages, and not make that third page, until I reached the limit (3 images). Here is the code:[code]<? include 'header.php'; include 'db.php';?><div class="greentext">Select the photo you would like to view:<br /><br /><? $num = $_GET['num'];if(empty($num)){$num = 1;};$limit = 3;$start = ($num-1)*$limit;$start = round($start,0);$sql = "SELECT * FROM `gallery` ORDER by `id` LIMIT $start, $limit";$result = mysql_query($sql); while ($row = mysql_fetch_array($result)) { echo "<a href='viewgallery.php?id=$row[id]'><img src='galleryimages/$row[picture]' width='222' height='167' style='border: 2px solid #d4cccc;'> </a>";}?><br /><br /><?$totalpages = mysql_num_rows(mysql_query("SELECT * from `gallery`"));$totalpages = $totalpages / $limit;$totalpages = round($totalpages,0);$c = 0;while($c<$totalpages){$page = $c + 1;if($_GET['num']==$page){echo " [$page]";}else{echo " <a href=?num=$page>[$page]</a>";}$c = $c+1;}echo "<br>".$totalpages." Pages in total."; ?> </div><? include 'footer.php'; ?>[/code]Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/16606-question-with-pagination/ Share on other sites More sharing options...
redarrow Posted August 5, 2006 Share Posted August 5, 2006 try this mate ok[code]<? include 'header.php';include 'db.php';?><div class="greentext">Select the photo you would like to view:<br /><br /><?phpif(!isset($_GET['page'])){ $page = 1; } else { $page = $_GET['page']; } $max_results = 3; $from = (($page * $max_results) - $max_results); $query="select * FROM `gallery` ORDER by `id` LIMIT $from, $max_results";$result=mysql_query($query);while($row=mysql_fetch_assoc($result)){<a href='viewgallery.php?id=$row[id]'><img src='galleryimages/$row[picture]' width='222' height='167' style='border: 2px solid #d4cccc;'> </a>";$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM FROM gallery "),0); $total_pages = ceil($total_results / $max_results); if($page > 1){ $prev = ($page - 1); echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$prev\"></a>"; } for($i = 1; $i <= $total_pages; $i++){ if(($page) == $i){ echo "$i "; } else { echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i\">$i</a> "; } } if($page < $total_pages){ $next = ($page + 1); echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next\"></a>";} }?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/16606-question-with-pagination/#findComment-69569 Share on other sites More sharing options...
gfX Posted August 5, 2006 Author Share Posted August 5, 2006 Didn't work man, There were a few errors which I fixed up but that code isn't working :( Quote Link to comment https://forums.phpfreaks.com/topic/16606-question-with-pagination/#findComment-69575 Share on other sites More sharing options...
redarrow Posted August 5, 2006 Share Posted August 5, 2006 hundred of users use it daily look here the full code i use ok.[code]<?php$db=mysql_connect("localhost" , "xxxx" , "xxxx");mysql_select_db("promotor",$db);?><html><head><title>Send Message</title><body bgcolor="#A0C0F0"><br><br><br><br><br><?phpif(!isset($_GET['page'])){ $page = 1; } else { $page = $_GET['page']; } $max_results = 1; $from = (($page * $max_results) - $max_results); $query="select * from messages_copied LIMIT $from, $max_results";$result=mysql_query($query);while($record=mysql_fetch_assoc($result)){echo"<table align='center' width='300'border='4' bordercolor='black'><td align='left'><b>Members Id:<font color='red'><br>".$record["sent_id"]."</font><br> User Name: <font color='red'><br>".$record["members_name"]."</font><br>Sent Time: <font color='red'><br>".$record["time"]."</font> <br> Sent Date <font color='red'><br>".$record["date"]."</font> </b></td><td align='center' valign='top'><b>Members Message <font color='red'>$page</font><b><br><br><b><div align='left'><textarea col='7' rows='7'style='color: white; background-color: #A0C0F0'>".$record["message"]."</textarea></td></b></div><table>";echo "<table align='center' width='300'border='4' bordercolor='black'><td align='center'><b>";$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM messages_copied "),0); $total_pages = ceil($total_results / $max_results); echo "<center><b>Select A Message!</b><br>"; if($page > 1){ $prev = ($page - 1); echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$prev\"></a>"; } for($i = 1; $i <= $total_pages; $i++){ if(($page) == $i){ echo "$i "; } else { echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i\">$i</a> "; } } if($page < $total_pages){ $next = ($page + 1); echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next\"></a>";} echo "</center>"; echo'</td></table>';echo "<table align='center' width='300'border='4' bordercolor='black'><td align='center'><b>Send A Reply <font color='red'><a href='reply_message.php?&id=".$record['sent_id']."'>Reply</a></b></font><font color='red'><a href='delete_message.php?&cmd=delete&time=".$record['time']."&id=".$record['sent_id']."'>Delete</a></b></font></td></table><br>";}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/16606-question-with-pagination/#findComment-69576 Share on other sites More sharing options...
gfX Posted August 5, 2006 Author Share Posted August 5, 2006 I don't get what that has to do with it. Quote Link to comment https://forums.phpfreaks.com/topic/16606-question-with-pagination/#findComment-69602 Share on other sites More sharing options...
HeyRay2 Posted August 5, 2006 Share Posted August 5, 2006 Let's say, for example, that you have 16 results, at 3 results per page.If you use this code:[code]$totalpages = $totalpages / $limit;$totalpages = round($totalpages,0);[/code]You will get a result of [b]5.33[/b] pages, which will get rounded down to [b]5[/b] with [b]round()[/b].Change this line in your code:[code]$totalpages = $totalpages / $limit;[/code]to this:[code]$totalpages = ceil($totalpages / $limit);[/code]and remove this line:[code]$totalpages = round($totalpages,0);[/code]That will give you [b]6[/b] pages as your result in my example, which should fix your issue. Quote Link to comment https://forums.phpfreaks.com/topic/16606-question-with-pagination/#findComment-69616 Share on other sites More sharing options...
gfX Posted August 5, 2006 Author Share Posted August 5, 2006 Thank you very much!This is random but how do you remove a file from FTP using PHP? Quote Link to comment https://forums.phpfreaks.com/topic/16606-question-with-pagination/#findComment-69755 Share on other sites More sharing options...
ignace Posted August 5, 2006 Share Posted August 5, 2006 ftp what do you mean? when it is already uploaded or still has to be uploaded? When it is already uploaded you will need unlink(); to delete the file. Quote Link to comment https://forums.phpfreaks.com/topic/16606-question-with-pagination/#findComment-69760 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.