/    Sign up×
Community /Pin to ProfileBookmark

looping structures

Hi all

I tried a shot in the dark with this but no go…I though I’d post it to see if I was heading on the right area.

here is the script…. a bit ruff still but hey…..baby steps.

it has a few problems but one at a time, I would like to have it loop the structure so there are 3 images across and 2 down.

[code=php]
<?php
//Variables
if (isset($_GET[“num1”])){
if ($_GET[“num1”] > 0){
$num1 = $_GET[“num1”];
}
else{
$num1 = 1;
}
}
else{
$num1 = 1;
}
if (isset($_GET[“num2”])){
if ($_GET[“num1”] > 0){
$num2 = $_GET[“num2”];
}
else{
$num2 = 6;
}
}
else{
$num2 = 6;
}

//Path
$path = “gallery/”;
$loc = explode(“/”, $_SERVER[“PHP_SELF”]);
$loc = $loc[(count($loc) – 1)];

// Open the folder
$dir_handle = @opendir($path) or die(“Unable to open $path”);
$num = $num1;
// Loop through the files
echo ‘<table border=”0″ align=”center”>’;
while ((false !== ($file = readdir($dir_handle))) && ($num >= $num1 && $num < $num2)){ // Check the numbers from the original GETs.
if ($file != “.” || $file != “..” || $file != $loc){
$files = array();
$pieces = explode(‘.’, $file);
$extension = $pieces[(count($pieces) – 1)];
$image = $pieces;
if( $extension == “jpg”){
echo “<tr>”;
echo “<td>$num<div align=’center’><img width=”100″ height=”100″ src='” . $path . $image[0] . “.” . $extension . “‘></div><div align=’center’>” . $image[0] . “</div></td>”;
$num++ ;
echo “<td>$num<div align=’center’><img width=”100″ height=”100″ src='” . $path . $image[0] . “.” . $extension . “‘></div><div align=’center’>” . $image[0] . “</div></td>”;
$num++ ;
echo “<td>$num<div align=’center’><img width=”100″ height=”100″ src='” . $path . $image[0] . “.” . $extension . “‘></div><div align=’center’>” . $image[0] . “</div></td>”;
$num++ ;
echo “</tr>”;
}

}
}
echo ‘</table>’;
echo ‘<div align=”center”>’;
echo ‘<br>’;
if (($num1 – 6) > 0){
echo ‘<a href=”‘ . $loc . ‘?num1=’ . ($num1 – 6) . ‘&num2=’ . ($num2 – 6) . ‘”><strong>BACK</strong></a>’;
echo ‘ | ‘;
}
else{
}
echo ‘<a href=”‘ . $loc . ‘?num1=’ . ($num1 + 6) . ‘&num2=’ . ($num2 + 6) . ‘”><strong>NEXT</strong></a>’;
echo ‘</div>’;
// Close
closedir($dir_handle);
?>
[/code]

This formats it the way I want but Doesn’t give different images across…I not to sure how to do that I thought maybe something like: $image[0] then $image[1] and $image[2] but I tried that and still no go.

The good part was that the $num number where all set out correctly.

Try it and you’ll see what I meen.
here is a link to a demo of the script so far:

[URL=http://members.lycos.co.uk/cybercampbell/gallery/gallery.php]http://members.lycos.co.uk/cybercampbell/gallery/gallery.php[/URL]

and here is a link to the original post if you’d like to have a go at the other issues with the script.

[URL=http://www.webdeveloper.com/forum/showthread.php?s=&postid=243087#post243087]http://www.webdeveloper.com/forum/showthread.php?s=&postid=243087#post243087[/URL]

Cheers
Chris

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @cybercampbell spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...