ShoeLace1291 Posted November 9, 2007 Share Posted November 9, 2007 I have a page that gets all the php files in a certain folder and displays them. It's a foreach loop, but for some reason I'm getting an infinite loop. This is my code: <?php echo "<table align='center' cellspacing='2' cellpadding='2' border='0'> <tr>"; $rows = 0; foreach(glob('forums/*.php') as $szFilename){ $rows = $rows + 1; echo "<td style='text-align: center;'><img src='images/icon_phpfile.png' alt='PHP File'><br>$szFilename</td>"; if($rows == { echo "</tr><tr>"; } } echo "</tr></table>"; ?> Quote Link to comment Share on other sites More sharing options...
Orio Posted November 9, 2007 Share Posted November 9, 2007 Should be a problem here.... Try: <?php echo "<table align='center' cellspacing='2' cellpadding='2' border='0'> <tr>"; $rows = 0; $files = glob('forums/*.php'); foreach($files as $szFilename){ $rows = $rows + 1; echo "<td style='text-align: center;'><img src='images/icon_phpfile.png' alt='PHP File'><br>$szFilename</td>"; if($rows == { echo "</tr><tr>"; } } echo "</tr></table>"; ?> Orio Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted November 9, 2007 Share Posted November 9, 2007 I noticed two problems with your code. 1) You should increment the counter after formating the line 2) You should test if the remainder of the $rows / 8 is 0 Try: <?php echo "<table align='center' cellspacing='2' cellpadding='2' border='0'> <tr>"; $rows = 0; foreach(glob('*.php') as $szFilename){ echo "<td style='text-align: center;'><img src='images/icon_phpfile.png' alt='PHP File'><br>$szFilename</td>"; $rows++; if($rows % 8 == 0) echo "</tr><tr>"; } echo "</tr></table>"; ?> Ken Quote Link to comment Share on other sites More sharing options...
ShoeLace1291 Posted November 10, 2007 Author Share Posted November 10, 2007 Is there any way to display the filename without the name of the directory in front of it? so instead of forums/index.php would display as just index.php. Also, what arguement would I use for the first one if I only want to get the name of a directory? glob('here', GLOB_ONLYDIR); Quote Link to comment Share on other sites More sharing options...
Orio Posted November 10, 2007 Share Posted November 10, 2007 Check dirname() and basename(). Orio. 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.