cdog1912 Posted December 15, 2008 Share Posted December 15, 2008 I need some help to change the one coloum table to a 5 row and 3 coloum table. This is the script: <?php $dir = 'path to directory'; $dirHandle = opendir($dir); $image = ""; while ($file = readdir($dirHandle)) { if(strpos($file, '.gif')>0) { $count++; $image[$count] = array ($file); } } sort($image); closedir($dirHandle); $arrays = count($image) -1; $loop = -1; $c = 0; while ($loop < $arrays) { $loop++; if ($c == 4) { echo '</tr><tr><td><img src="the-directory/'.$image[$loop][0].'"></td>'; $c = 0; } else { echo '<td><img src="the-directory/'.$image[$loop][0].'"></td>'; } $c++; } if ($c==1) {echo '<td colspan="3"></td>';} if ($c==2) {echo '<td colspan="2"></td>';} if ($c==3) {echo '<td></td>';} if ($c==4) {echo '';} ?> </tr> </table> any help would be great thanks Quote Link to comment Share on other sites More sharing options...
flyhoney Posted December 16, 2008 Share Posted December 16, 2008 Hows about this? <?php $dir = 'images'; $dirHandle = opendir($dir); $images = array(); while ($file = readdir($dirHandle)) { if(strpos($file, '.gif') !== false) { $images[] = $file; } } sort($image); closedir($dirHandle); $col = 0; echo "<table><tr>"; foreach ($images as $image) { echo ($col % 3 == 0)? "</tr><tr>" : ""; echo '<td><img src="'.$dir.'/'.$image.'" /></td>'; $col++; } echo "</tr></table>"; ?> Quote Link to comment Share on other sites More sharing options...
flyhoney Posted December 16, 2008 Share Posted December 16, 2008 Also check out this: http://www.phpfreaks.com/forums/index.php/topic,95426.0.html Quote Link to comment Share on other sites More sharing options...
cdog1912 Posted December 16, 2008 Author Share Posted December 16, 2008 thanks i will give it a try Quote Link to comment Share on other sites More sharing options...
flyhoney Posted December 16, 2008 Share Posted December 16, 2008 Sorry, noticed there were some errors: <?php $dir = 'images'; $dirHandle = opendir($dir); $images = array(); while ($file = readdir($dirHandle)) { if(strpos($file, '.gif') !== false) { $images[] = $file; } } sort($images); closedir($dirHandle); $col = 1; echo '<table><tr>'; foreach ($images as $image) { echo ($col % 3 == 0) ? '</tr><tr>' : ''; echo '<td><img src="'.$dir.'/'.$image.'" /></td>'; $col++; } echo '</tr></table>'; ?> Quote Link to comment 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.