PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
kaveret
Forum Newbie
Posts: 6 Joined: Fri May 28, 2004 3:36 am
Post
by kaveret » Fri May 28, 2004 3:36 am
Otay i just need a lil help, you see im trying to make a gallery script and ive had help, but i have a prob and im asking if anyone can help me...
okie, im trying to get the following script to display 20 images per page, but if theres like 23 i want 3 on page 2, this way i can use the same script for each directory(im making an anime site and i have a total of 154 gallerys ^_^ and the # of pic differ in each gallery, i host all the pics from my own pc ^_^) now the prob w\ this script is that if theres 23pics it only shows 20 but if theres like 16 it will show pics of x's. TT_TT please please help me TT_TT
p.s. i have it set up so it reads a fake pic like 1x1px and it opens a bigger pic on my server, u can see what i mean at
http://falconxanime.tk
This is index.php
Code: Select all
<?php
include("../../Header.php");
include("anime.php");
include("../../Navigation.php");
include("../Body.php");
//Variables
$images=20;
$a=0;
$filepath = 'images/';
$url_path = 'images/';
$dir = dir($filepath);
//grab start
if(isset($_GET['next']) && is_numeric($_GET['next']))
{
$start=$_GET['next'];
}
elseif(isset($_GET['pre']) && is_numeric($_GET['pre']))
{
$start=$_GET['pre'];
}else{
$start=0;
}
if($start<0){$start=0;}
$pos=$start;
//Table Setup
echo "<table border="0" cellpadding="3" cellspacing="3" width="100%"><tr>";
while($image=$dir->read()) {
if($image == "." || $image == "..") {
continue;
}
$imagearray[]=$image;
}
//set limits
$count=count($imagearray);
if($start>$count-$images)
{
$start=$count-$images;
}
$limit=$start+$images;
// loop through array from start
for($i=$start;$i<$limit;$i++)
{
//Table Return
//Link
if ($a%5==0) {echo "</tr><tr>";}
echo"<td><a href="http://falconxanime.homelinux.com:82/Anime/".$anime."/".$imagearray[$i]."">";
echo"<img src="http://falconxanime.homelinux.com:82/Anime/".$anime."/tn/".$imagearray[$i]."" alt="".$anime."-".$imagearray[$i].""></a></td>";
$a++;
}
echo"</tr></table>";
?>
<br>
<?
//display next previous
if($start>0)
{
$pre=$pos-$images;
echo"<center><a href="".$_SERVER['PHP_SELF']."?pre=".$pre."" >Previous</a> ";
}
if($start<$count-$images)
{
$nex=$pos+$images;
echo"<center><a href="".$_SERVER['PHP_SELF']."?next=".$nex."" >Next</a> ";
} ?>
<?
include("../../footer.php");
?>
this is anime.php i use this so i dont have to change the index.php for each directory
Last edited by
kaveret on Sat May 29, 2004 2:53 am, edited 1 time in total.
Grim...
DevNet Resident
Posts: 1445 Joined: Tue May 18, 2004 5:32 am
Location: London, UK
Post
by Grim... » Fri May 28, 2004 5:23 am
Not the best solution, but:
Send a variable with the picture number you are on to the page (20, 40, etc), maybe using a hyperlink:
Code: Select all
$start_image += 20;
print "<a href="anime.php?start_image=$start_image">Next Page</a>";
Now, while you are looping through the array:
Code: Select all
if ($i < $start_image) {
continue;
}
and to make sure you only display 20 images per page:
Code: Select all
if ($i > ($start_image + 20) {
break;
}
Hope this helps.
kaveret
Forum Newbie
Posts: 6 Joined: Fri May 28, 2004 3:36 am
Post
by kaveret » Fri May 28, 2004 7:40 am
wha? o.o im sorry i should have stated im a n00b i kinda know what that does but o.o where does it go in the code TT_TT (im baka) btw thx for helping <.< i wish i knew what u ment lol im gonna keep tring that untill its works
Grim...
DevNet Resident
Posts: 1445 Joined: Tue May 18, 2004 5:32 am
Location: London, UK
Post
by Grim... » Fri May 28, 2004 8:26 am
Okay, you want to show 20 at once, right?
Change this bit of code:
Code: Select all
for($i=$start;$i<$limit;$i++)
{
//Table Return to
Code: Select all
for($i=$start;$i<$limit;$i++)
{
if ($i < $start_image) {
continue;
}
if ($i > ($start_image + 20) {
break;
}
//Table Return
And after you've displayed the images, you'll want some hyperlinks so the user can go to the next / previous page, right?
Code: Select all
$back_image = $start_image - 20;
$start_image += 20;
print "<a href="anime.php?start_image=$back_image">Back a page</a> | <a href="anime.php?start_image=$start_image">Next Page</a>";
Better?
kaveret
Forum Newbie
Posts: 6 Joined: Fri May 28, 2004 3:36 am
Post
by kaveret » Fri May 28, 2004 9:11 am
i tried a a couple other ways to but nothing worked right... im just gonna have 2 make it so each gallery has images in multiples of 20 lol thank you for your time and help.... btw love ur site ~^_^~ (i have a feeling im cursed to have bad luck with everything ^_^)
Code: Select all
<?php
$name = "grim ";
$act = "rock";
$end = "s ";
$humor = ;
print "$name$act$end$humor";
?>
Grim...
DevNet Resident
Posts: 1445 Joined: Tue May 18, 2004 5:32 am
Location: London, UK
Post
by Grim... » Fri May 28, 2004 9:35 am
Don't give up, never give up, you'll never learn that way.
Why not use an SQL database to store the links, and call them from that?
Grim...
DevNet Resident
Posts: 1445 Joined: Tue May 18, 2004 5:32 am
Location: London, UK
Post
by Grim... » Fri May 28, 2004 9:35 am
There's always more than one way to solve a problem
kaveret
Forum Newbie
Posts: 6 Joined: Fri May 28, 2004 3:36 am
Post
by kaveret » Fri May 28, 2004 7:46 pm
because i use this structure
Gallery/(anime name)/images/*.jpg
and the jpgs here are 1x1 px so i dont use bandwidth so it sees the name of the file and just uses the name like 01.jpg then i have it open 01.jpg off of my pc
(for thumbs)
http://falconxanime.homelinux.com:82/Anime/$anime/tn/
(for big image)
http://falconxanime.homelinux.com:82/Anime/$anime/
this way i can have 20gb of pictures with out paying for a hosting plan
the script i have does that...but if theres only say 5 pics in a dir it will show 15 unavailable pics of the folder
example:
http://falconxanime.anyxhost.com/Gallery/6angels/
all i need to know is how to get it to display only the pictures what ever the # the script has pages but they only show 20 pics per page abd if theres 41pics it will only show 2 pages and wont show the last pic ....see my prob
kaveret
Forum Newbie
Posts: 6 Joined: Fri May 28, 2004 3:36 am
Post
by kaveret » Fri May 28, 2004 7:49 pm
its just too many pics to link individualy
kettle_drum
DevNet Resident
Posts: 1150 Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England
Post
by kettle_drum » Fri May 28, 2004 8:27 pm
Use ceil() around the number of pages:
Code: Select all
$show_per_page = 20;
$total_number = work_out_number(); //e.g. 43
$pages = ceil($total_number/$show_per_page);
//$pages = 3 ... ceil rounds a number up to the next whole number
kaveret
Forum Newbie
Posts: 6 Joined: Fri May 28, 2004 3:36 am
Post
by kaveret » Sat May 29, 2004 2:48 am
i decided to change my layout (my gf wanted me to(she has dialup) lol) otay im making it 1 pic at a time so i decided to post the code incase some one wanted the same design
here she is:
Code: Select all
<?php
###########
##Include##
###########
include("Header.php");
include("anime.php");
include("Navigation.php");
include("Body.php");
#############
##Variables##
#############
$images=1;
$a=0;
$filepath = 'images/';
$url_path = 'images/';
$dir = dir($filepath);
$main = "http://falconxanime.homelinux.com:82/Anime/$anime";
$thumb = "http://falconxanime.homelinux.com:82/Anime/$anime";
##############
##grab start##
##############
if(isset($_GET['next']) && is_numeric($_GET['next']))
{
$start=$_GET['next'];
}
elseif(isset($_GET['pre']) && is_numeric($_GET['pre']))
{
$start=$_GET['pre'];
}else{
$start=0;
}
if($start<0){$start=0;}
$pos=$start;
###############
##Image Array##
###############
while($image=$dir->read()) {
if($image == "." || $image == "..") {
continue;
}
$imagearray[]=$image;
}
##############
##set limits##
##############
$count=count($imagearray);
if($start>$count-$images)
{
$start=$count-$images;
}
$limit=$start+$images;
#################################
##loop through array from start##
#################################
for($i=$start;$i<$limit;$i++)
{
###########################
##display next / previous##
###########################
if($start>0)
{
$pre=$pos-$images;
echo"<center><a href="".$_SERVER['PHP_SELF']."?pre=".$pre."" >Previous</a> ";
}
if($start<$count-$images)
{
$nex=$pos+$images;
echo"<center><a href="".$_SERVER['PHP_SELF']."?next=".$nex."" >Next</a> ";
}
###############
##Table Setup##
###############
echo "<table border="0" cellpadding="3" cellspacing="3" width="100%"><tr>";
#####################
##Link And Pictures##
#####################
if ($a%5==0) {echo "</tr><tr>";}
echo"<td><center><a href='$main/$imagearray[$i]'>";
echo"<img src='$thumb/$imagearray[$i]' alt='$anime-$imagearray[$i]'></a></td>";
$a++;
}
echo"</tr></table>";
##########
##Footer##
##########
include("footer.php");
?>