php - Display images in html table (IF loop) -


i'm looking write php script post images directory table format 8 columns wide , rows extend many images there are. current code have posts them in separate rows. how can divide them rows of 8 images?

<?php  $files = glob("images/*.*"); ($i=1; $i<count($files); $i++) {     $image = $files[$i];     $supported_file = array(         'gif',         'jpg',         'jpeg',         'png'     );      $ext = strtolower(pathinfo($image, pathinfo_extension));     if (in_array($ext, $supported_file)) {         // print $image ."<br />";         echo '<a href="' .$image .'"><img src="'.$image .'" alt="random image" width=200 /></a>'."<br /><br />";     } else {         continue;     } } ?> 

something this? $i % 8 returns 0 every 8th row stop stop/start <tr> tag basically.

<table>     <tr>         <?php         $files = glob("images/*.*");         ($i = 1; $i < count($files); $i++) {             $image = $files[$i];             $supported_file = array(                 'gif',                 'jpg',                 'jpeg',                 'png'             );              $ext = strtolower(pathinfo($image, pathinfo_extension));             if (in_array($ext, $supported_file)) {                 // print $image ."<br />";                 echo '<td><a href="' . $image . '"><img src="' . $image . '" alt="random image" width=200 /></a></td>';             }             if ($i % 8 === 0) {                 echo "</tr><tr>";             }         }         ?>     </tr> </table> 

Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -