corillo181 Posted April 27, 2006 Share Posted April 27, 2006 why those this doesn't show up the images?[code]<?$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><a href=$path/$file><img height=\"100\" width=\"100\" src=$path/$file></a></td> "; } echo "</tr>";}closedir($handle);?></table>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/8524-solved-opendir/ Share on other sites More sharing options...
wisewood Posted April 27, 2006 Share Posted April 27, 2006 This will display all files of the type you specify in the directory you specify.Using *.jpg will display all jpg files.. obviously.[code]<?phpforeach (glob("/Gallery/thumbs/*.jpg") as $filename) {echo "<IMG SRC='$filename' ALT='$filename'><br>";}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/8524-solved-opendir/#findComment-31270 Share on other sites More sharing options...
corillo181 Posted April 27, 2006 Author Share Posted April 27, 2006 i used that code and tried to use it with a table and it returns the amount of pictures per row the same one, if i put 5 rows it show the first pitures 5 times than the next row 5 pics of the same and so on..[code]<table border="1"><?php$dir = "Gallery/thumbs/";$row=2;$col=2;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>";closedir($dir);}?><table>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/8524-solved-opendir/#findComment-31392 Share on other sites More sharing options...
corillo181 Posted April 27, 2006 Author Share Posted April 27, 2006 man can someone just answer this question! Quote Link to comment https://forums.phpfreaks.com/topic/8524-solved-opendir/#findComment-31429 Share on other sites More sharing options...
kenrbnsn Posted April 27, 2006 Share Posted April 27, 2006 As I understand your question, you're trying to display your pictures n to a row for as many rows it takes.The reason the current code doesn't work is that the "for" loops are within the foreach loop that select the picture.Try this:[code]<?php$cols = 5;$cnt = 0;$tmp = array();$tmp2 = array();foreach (glob("$dir/*.jpg") as $filename) { $tmp2[] = '<td><IMG SRC="' . $filename . '"></td>'; $cnt++; if ($cnt % $cols == 0) { $tmp[] = implode('',$tmp2); $tmp2 = array(); }}echo "<tr>\n" . implode("</tr>\n<tr>",$tmp) . "</tr>\n";?>[/code]The "%" is the [a href=\"http://us2.php.net/manual/en/language.operators.arithmetic.php\" target=\"_blank\"]modulus operator[/a]This code will take each filename and put the string '<td><img ... ></td>' into the array $tmp2. When the number of pictures processed divided by the number of columns is zero, use implode to combine those strings into one and put it into the $tmp array.When there are no more pictures to process, use the implode() function to put the string "</tr>\n<tr>" between those strings.KenYou also can remove the "closedir($dir)" statement.Ken Quote Link to comment https://forums.phpfreaks.com/topic/8524-solved-opendir/#findComment-31453 Share on other sites More sharing options...
corillo181 Posted April 27, 2006 Author Share Posted April 27, 2006 yeaaaaaaaaaaaaaaaaaaaaaaaaaaah.. thats what i was looking for.. :-D bout time.. thank you very much ken :) Quote Link to comment https://forums.phpfreaks.com/topic/8524-solved-opendir/#findComment-31465 Share on other sites More sharing options...
corillo181 Posted April 27, 2006 Author Share Posted April 27, 2006 oh wait one last thing.. how do i do to break it for another row..i try my ways but i'm getting no where..hope i'm not been to muhc trouble :| Quote Link to comment https://forums.phpfreaks.com/topic/8524-solved-opendir/#findComment-31470 Share on other sites More sharing options...
kenrbnsn Posted April 27, 2006 Share Posted April 27, 2006 What do you mean?Ken Quote Link to comment https://forums.phpfreaks.com/topic/8524-solved-opendir/#findComment-31490 Share on other sites More sharing options...
corillo181 Posted April 28, 2006 Author Share Posted April 28, 2006 [!--quoteo(post=369399:date=Apr 27 2006, 07:53 PM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ Apr 27 2006, 07:53 PM) [snapback]369399[/snapback][/div][div class=\'quotemain\'][!--quotec--]What do you mean?Ken[/quote] like if i have 6 pictures that are showing in a row.. and i want then to show and different rows likethis is how they show |1|1|1|1|1|1|and this is wha yti'm trying to get|1|1||1|1||1|1|in 3 rows..like with the td the more pictures i add the line get larger, i want to breake it in to rows.. Quote Link to comment https://forums.phpfreaks.com/topic/8524-solved-opendir/#findComment-31500 Share on other sites More sharing options...
kenrbnsn Posted April 28, 2006 Share Posted April 28, 2006 In my code, just make the variable "$cols" to be equal to the number of columns you want.I just found a small bug with my code while testing to make sure the above worked. :-)Just before this line [code]<?php echo "<tr>\n" . implode("</tr>\n<tr>",$tmp) . "</tr>\n"; ?>[/code]Add the line [code]<?php if (!empty($tmp2)) $tmp[] = implode('',$tmp2); ?>[/code]This takes care of any pictures on the last line.Ken Quote Link to comment https://forums.phpfreaks.com/topic/8524-solved-opendir/#findComment-31546 Share on other sites More sharing options...
corillo181 Posted April 28, 2006 Author Share Posted April 28, 2006 yeah that solves the problem.. well thank you very much man :) Quote Link to comment https://forums.phpfreaks.com/topic/8524-solved-opendir/#findComment-31560 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.