Jump to content

Limite to 10 pages


drisate

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/160063-limite-to-10-pages/
Share on other sites

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());

Link to comment
https://forums.phpfreaks.com/topic/160063-limite-to-10-pages/#findComment-844447
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/160063-limite-to-10-pages/#findComment-844472
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.