Page 1 of 1
Next Previous Links for PHP Photo Gallery Script
Posted: Sun Jun 08, 2003 11:03 am
by nightmatrix
Hi My name is Andrew
I am having newbie trouble trying to add next previous links to my script (well it's not my script) if anyone can help it would be much appreciated
Code: Select all
<?php
$a = '0';
$filepath = "thumb";
$url_path = "bw";
$dir = dir($filepath);
echo "<table width="100%" border="0" cellpadding="5" cellspacing="5">";
while($entry=$dir->read()) {
if($entry == "." || $entry == "..") {
continue;
}
$fp = @fopen("$filepath/$entry","r");
if ($a == '0') {echo "<tr>";}
if ($a == '5') {echo "<tr>";}
if ($a == '10') {echo "<tr>";}
if ($a == '15') {echo "<tr>";}
?><td>
<a href="javascript:location='bw.php'; window.open('<? echo "$url_path/$entry" ?>', 'characters', 'HEIGHT=480, WIDTH=640, scrollbars=no')">
<img src="<? echo "$filepath/$entry" ?>" alt="<? echo $entry ?>"></a>
</td>
<?
$a = $a + 1;
}
?>
?>
"If I posted this script wrong please let me know"
Thanks in Advance
Andrew
?>
Re: Next Previous Links for PHP Photo Gallery Script
Posted: Sun Jun 08, 2003 3:23 pm
by delorian
Well, could you tell where you want to add those next, previous links. As far as understand your script, it displays pictures from a folder 5 in every row. I rewrited this script:
Code: Select all
<?php
$a = '0';
$filepath = "thumb";
$url_path = "bw";
$dir = dir($filepath);
echo "<table width="100%" border="0" cellpadding="5" cellspacing="5">";
while($entry=$dir->read()) {
if($entry != "." && $entry != "..") {
// $fp = @fopen("$filepath/$entry","r"); ---- this is unecessary
if (!($a%5)) {echo "<tr>";}
?>
<td>
<a href="javascript:location='bw.php'; window.open('<?php echo "$url_path/$entry" ?>', 'characters', 'HEIGHT=480, WIDTH=640, scrollbars=no')">
<img src="<?php echo "$filepath/$entry" ?>" alt="<?php echo $entry ?>"></a>
</td>
<?php
$a++;
if (!($a%5) && $a!=0) { echo "</tr>"; }
} // end of if
} // end of while
?>
Posted: Sun Jun 08, 2003 3:31 pm
by nightmatrix
I would like to put the links below the images
Thanks Andrew
I see now
Posted: Sun Jun 08, 2003 3:48 pm
by nightmatrix
I see what your saying now it displays every image in the folder with five in every row I didn't realize that
I guess what I am looking for is to be able to Display a maximum of 20 pictures 5 in each row 4 columns and have sub folders from the main directory that I can link to another 20 images maybe it would make more sense to choose it by numbers instead of next previous links I can do this manually in HTML
Thats probably easier
Anyway
Thank You
Andrew
Posted: Sun Jun 08, 2003 4:11 pm
by delorian
Hmmm... try this:
Code: Select all
<?php
$a = 0;
$filepath = "thumb";
$url_path = "bw";
$dir = dir($filepath);
$start=0;
$stop=20;
if(!empty($_GET['start']) && !empty($_GET['stop'])) {
$start=intval($_GET['start']);
$stop=intval($_GET['stop']);
}
echo "<table width="100%" border="0" cellpadding="5" cellspacing="5">";
while($entry=$dir->read()) {
if($a>=$start && $a<$stop) { // $a<$stop because from 0-19 you have 20 pictures
if($entry != "." && $entry != "..") {
if (!($a%5)) {echo "<tr>";}
?>
<td>
<a href="javascript:location='bw.php'; window.open('<?php echo "$url_path/$entry" ?>', 'characters', 'HEIGHT=480, WIDTH=640, scrollbars=no')">
<img src="<?php echo "$filepath/$entry" ?>" alt="<?php echo $entry ?>"></a>
</td>
<?php
$a++;
if (!($a%5) && $a!=0) { echo "</tr>"; }
} // end of if($entry
} // end of if($a>=
} // end of while
?>
</table>
<?php
if($start>=20) {
echo "<a href="".$PHP_SELF."?start=".$start-20."&stop=".$start."">previous</a>";
}
echo " ";
echo "<a href="".$PHP_SELF."?start=".$stop."&stop=".$stop+20."">next</a>";
?>
I'm sorry I didn't check this script, but I don't have the access to my serwer from where I write this post. But it should be good.
Of course it's far from good php code.
Posted: Sun Jun 08, 2003 5:15 pm
by nightmatrix
Hey Delorian
Thanks for all your help so far
but there is an error in that script unexpected T_CONSTANT_ENCAPSED_STRING expecting "," or ";"
I tried for a little while to fix this on my own, so I don't feel totally useless
but to know avail the error is on line 45
If you come back to this post any help would be appreciated thanks Andrew
a quick fix
Posted: Sun Jun 08, 2003 5:47 pm
by phpScott
I ran Delorian through my editor and it didn't like the $start-20 or $stop+20 code so I tweaked it and placed that little section below. Try it out to see if that will work.
It belongs inside the last set of php tags.
Code: Select all
if($start>=20) {
$start2=$start-20;
echo "<a href="".$PHP_SELF."?start=".$start2."&stop=".$start."">previous</a>";
}
echo " ";
$stop2=$stop+20;
echo "<a href="".$PHP_SELF."?start=".$stop."&stop=".$stop2."">next</a>";
phpScott
Posted: Sun Jun 08, 2003 6:10 pm
by nightmatrix
Hey Thanks
It seems to be working fine however it won't display the Images on the second page I thought maybe there had to be 20 more images to display is this correct
Thanks
Andrew
Does'nt work 100% Percent
Posted: Sun Jun 08, 2003 6:36 pm
by nightmatrix
Hey PHP Scott
I tried uploading 20 more images and it still won't display them in the next section do you know how I can fix this
Thanks Andrew
Posted: Mon Jun 09, 2003 1:26 am
by delorian
Of course it didn't work, because, I've made a mistake (newbee-one)

That's the way you don't test your code, silly me...
How could this work if the $a wasn't increased at all, when the start was >=20.
Here's some update, I aslo add new variable $new_tr which controls adding new <tr> to your table. It should work. I still can't test it, I'm realy sorry.
Code: Select all
<?php
$a = 0;
$new_tr = 0;
$filepath = "thumb";
$url_path = "bw";
$dir = dir($filepath);
$start=0;
$stop=20;
if(!empty($_GET['start']) && !empty($_GET['stop'])) {
$start=intval($_GET['start']);
$stop=intval($_GET['stop']);
}
echo "<table width="100%" border="0" cellpadding="5" cellspacing="5">";
while($entry=$dir->read()) {
if($a>=$start && $a<$stop) { // $a<$stop because from 0-19 you have 20 pictures
if($entry != "." && $entry != "..") {
if (!($new_tr%5)) {echo "<tr>";}
?>
<td>
<a href="javascript:location='bw.php'; window.open('<?php echo $url_path."/".$entry; ?>', 'characters', 'HEIGHT=480, WIDTH=640, scrollbars=no')">
<img src="<?php echo "$filepath/$entry"; ?>" alt="<?php echo $entry; ?>"></a>
</td>
<?php
if (!($new_tr%5) && $new_tr!=0) { echo "</tr>"; }
} // end of if($entry
} // end of if($new_tr>=
$a++;
} // end of while
?>
</table>
<?php
if($start>=20) {
echo "<a href="".$PHP_SELF."?start=".$start-20."&stop=".$start."">previous</a>";
}
echo " ";
echo "<a href="".$PHP_SELF."?start=".$stop."&stop=".$stop+20."">next</a>";
?>
Posted: Mon Jun 09, 2003 11:18 am
by nightmatrix
Everything is Working fine, Except it is'nt displaying it in rows and columns it is just displaying it in one long line
Do you know how to fix this
Thank You
Andrew
Posted: Mon Jun 09, 2003 3:58 pm
by delorian
Here you are, the final version (still not-tested

):
Code: Select all
<?php
$a = 0;
$new_tr = 0;
$filepath = "thumb";
$url_path = "bw";
$dir = dir($filepath);
$start=0;
$interval=20; // how many pictures will be displayed
if(!empty($_GET['start'])) { $start=intval($_GET['start']); }
echo "<table width="100%" border="0" cellpadding="5" cellspacing="5">";
while($entry=$dir->read()) {
if($a>=$start && $a<($start+$interval)) { // $a<$start+$interval because from 0-19 you have 20 pictures
if($entry != "." && $entry != "..") {
if (!($new_tr%5)) {echo "<tr>";}
?>
<td>
<a href="javascript:location='bw.php'; window.open('<?php echo $url_path."/".$entry; ?>', 'characters', 'HEIGHT=480, WIDTH=640, scrollbars=no')">
<img src="<?php echo "$filepath/$entry"; ?>" alt="<?php echo $entry; ?>"></a>
</td>
<?php
$new_tr++;
if (!($new_tr%5) && $new_tr!=0) { echo "</tr>"; }
} // end of if($entry
} // end of if($new_tr>=
$a++;
} // end of while
?>
</table>
<?php
if($start>=20) {
echo "<a href="".$PHP_SELF."?start=".$start-20."">previous</a>";
}
echo "<a href="".$PHP_SELF."?start=".$start+20."">next</a>";
?>
As you can see I've used only start variable. That's better. And, of course now it should display 5 pictures in one row.
Hey Great it works
Posted: Mon Jun 09, 2003 5:57 pm
by nightmatrix
Hey Thanks
It works excellent now
You rock thanks so much
Cheers
Andrew