Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.