drisate Posted May 28, 2009 Share Posted May 28, 2009 hey guys i created a small photo gallery for a client. he asked 1 photo per page with a description. he has abbout 50 pages total. He would like only 10 pages listed at the time. so if the member is at page 11 page 11 should be in the middle [Previous] 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - 15 [Next] and if the guy is at 12 [Previous] 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - 15 - 16 [Next] This is the code i have so fare to liste the pages <?php $i=1; $phpecono1 = mysql_query("SELECT * FROM photo where id_page='$_GET[id]'") or die (mysql_error()); while($photo = @mysql_fetch_array($phpecono1)){ if ($_GET[photoid]=="$photo[id]"){$thiss="<strong>$i</strong>";}else{$thiss=$i;} print ('<td align="center" width="25"><font size="1" face="Verdana" color="#FFFFFF"><a href="index.php?mod=page&photoid='.$photo[id].'&id='.$_GET[id].'">'.$thiss.'</a></font></td>'); $i++;} ?> How can i limite to only 10 pages? Quote Link to comment https://forums.phpfreaks.com/topic/160063-limite-to-10-pages/ Share on other sites More sharing options...
paulman888888 Posted May 28, 2009 Share Posted May 28, 2009 this isn't answering your question but you query isn't safe $phpecono1 = mysql_query("SELECT * FROM photo where id_page='$_GET[id]'") or die (mysql_error()); should be something like; $id=mysql_real_escape_string($_GET['id']); $phpecono1 = mysql_query("SELECT * FROM photo where id_page='$id'") or die (mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/160063-limite-to-10-pages/#findComment-844447 Share on other sites More sharing options...
drisate Posted May 28, 2009 Author Share Posted May 28, 2009 i know ... i have a code that filtrer out the $_POST, $_GET, $_COOKIE, $_REQUEST, $_FILES vars in my header Quote Link to comment https://forums.phpfreaks.com/topic/160063-limite-to-10-pages/#findComment-844452 Share on other sites More sharing options...
jonsjava Posted May 28, 2009 Share Posted May 28, 2009 Here's a simple script to do what you are asking. it will return arrays of numbers that you can iterate through. <?php if (isset($_GET['page']) && is_int($_GET['page'])){ $page = $_GET['page']; } else{ $page = 1; } if ($page == 1){ $prev_few = array(); $next_few = range(2,10); } elseif ($page < 6){ $prev_few = range(1,($page - 1)); $next_few = range(($page + 1), 10); } else{ $prev_few = range(($page - 5),($page - 1)); $next_few = range(($page + 1), ($page + 4)); } ?> if you need help implementing it, feel free to ask. Quote Link to comment https://forums.phpfreaks.com/topic/160063-limite-to-10-pages/#findComment-844472 Share on other sites More sharing options...
sasa Posted May 28, 2009 Share Posted May 28, 2009 or <?php $page = 44; $total_pages = 50; $start = max(1, min($page - 5, $total_pages - 9)); $end = min($total_pages, max($page + 4, 10)); for ($i = $start; $i <= $end; $i++) { echo $i,' '; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/160063-limite-to-10-pages/#findComment-844496 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.