Page 1 of 1
looping problem
Posted: Wed Apr 26, 2006 3:07 pm
by corillo181
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
can someone tell me how to make this work? becuase if i put it in side the while it works, but it only loops the same file.
Code: Select all
<?
$path = "/Gallery/thumbs/";
$handle = opendir($path);
$row = 3;
$col = 3;
while(false !==($file = readdir($handle))){
if($file !="." && $file !=".."){
continue;
}
closedir($handle)
}
for($r=1;$r <= $row; $r++){
echo "<tr>";
for($c=1; $c <= $col; $c++){
echo "<td><img src=$path/$file[]></td>";
}
echo "</tr>";
}
?>
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Posted: Wed Apr 26, 2006 3:17 pm
by feyd
You don't need the for loops. What you do need is conditionals (if's) to know when and where to write out the table row ends.
Have a look at the first two threads referenced in Useful Posts.
Posted: Wed Apr 26, 2006 4:47 pm
by corillo181
mm can you just put the code in a way that would work so i can then fidgure it out that would be much better..
thank you if you do

..
Posted: Wed Apr 26, 2006 4:59 pm
by John Cartwright
corillo181 wrote:mm can you just put the code in a way that would work so i can then fidgure it out that would be much better..
thank you if you do

..
We can only show you the light, you have to walk the tunnel.
Posted: Wed Apr 26, 2006 6:25 pm
by corillo181
thats one tunel i'm having big problems with and i know if i get that i wont need any more help cuause i havent found a way to loop tabls like that and i guess i wont be doing any better if i keep trying.. i'm stuck here it wont hurt you and it would be a move on for me

Posted: Wed Apr 26, 2006 6:58 pm
by John Cartwright
As mentioned previously, look at the first two listings in the
Useful Post thread
Posted: Wed Apr 26, 2006 7:18 pm
by corillo181
thats the best i could come up with using the if , and it wont come out because i dont know ...i saw the other thread that i could do because is uusing the data base but i'm doing it while opening a directory..
Code: Select all
<table border="1">
<?
$path = "/Gallery/thumbs/";
$handle = opendir($path);
$row = 3;
$col = 3;
while(false !==($file = readdir($handle))){
if($file !="." && $file !=".."){
if($r=1;$r <= $row; $r++){
echo "<tr>";
if($c=1; $c <= $col; $c++){
echo "<td><img src=$path/$file></td>";
}
echo "</tr>";
}
}
}
?>
</table>
Posted: Wed Apr 26, 2006 11:18 pm
by corillo181
now i got it to wokr but my pictures wont display

can't help me with that either ?
Code: Select all
<table border="1">
<?
$path = "/Gallery/thumbs/";
$handle = opendir($path);
$row = 3;
$col = 3;
while(false !==($file = readdir($handle))){
if($file !="." && $file !=".."){
continue;
}
for($r=1;$r <= $row; $r++){
echo "<tr>";
}
for($c=1; $c <= $col; $c++){
echo "<td><img height='100' width='100' src=$path/$file></td>";
}
echo "</tr>";
}
closedir($handle);
?>
</table>
That should work
Posted: Wed Apr 26, 2006 11:36 pm
by dibyendrah
Is "Gallery " the sub-folder of the current script directory ?
Posted: Wed Apr 26, 2006 11:39 pm
by corillo181
it is a sub foder the scrip is bene places on a the same level as the gallery folder so i need the /gallery to go inside of it.. but i don't see why is not displaying .. just shows [x] and if i make the pictures a <a href> it just takes me to the directory .
Posted: Thu Apr 27, 2006 3:04 pm
by corillo181
i guess they really want me to find the light on my own..

do you know any place where they tut about displaying pictures? becuase every code i try always something wrong with it
Code: Select all
<table border="1">
<?php
$dir = "Gallery/thumbs/";
$row=4;
$col=4;
foreach (glob("$dir/*.jpg") as $filename)
{
for($r=1;$r <= $row; $r++){
echo "<tr>";
}
for($c=1; $c <= $col; $c++){
echo "<td><img src=$filename></td>";
}echo "</tr>";
}
?>
<table>
this one repeat the same image in every row..

Posted: Thu Apr 27, 2006 3:40 pm
by timvw
You are always outputting $filename... In a loop where only $c changes...
Posted: Thu Apr 27, 2006 3:45 pm
by corillo181
timvw wrote:You are always outputting $filename... In a loop where only $c changes...
oh how do i correct that?
Posted: Thu Apr 27, 2006 3:53 pm
by timvw
By reading (and understanding):
http://be2.php.net/manual/en/control-structures.for.php
Probably you want to checkout the other control structures too.
Posted: Thu Apr 27, 2006 3:58 pm
by corillo181
oh that great man exactly wha ti needed a site with exaplems 3 feet long
