php - Add tr after 4 uploaded images -
i want gallery of uploaded images, showing 4 images each tr. there needs loop somewhere can't work. needs add tr automatically when there 4 images in tr.
<?php $folder = 'uploads/'; $filetype = '*.*'; $files = glob($folder.$filetype); $count = count($files); $sortedarray = array(); ($i = 0; $i < $count; $i++) { $sortedarray[date ('ymdhis', filemtime($files[$i]))] = $files[$i]; } krsort($sortedarray); echo '<table>'; foreach ($sortedarray &$filename) { echo '<td align="center">'; echo '<a name="'.$filename.'" href="#'.$filename.'"><img src="'.$filename.'" /></a>'; echo 'bestand naam: ' . substr($filename,strlen($folder),strpos($filename, '.')-strlen($folder)); echo '</td>'; } echo '</table>'; ?>
use counter in loop. should :
echo '<table>'; $ctr = 0; foreach ($sortedarray &$filename) { echo ($ctr % 4 == 0) ? "<tr>" : ""; echo '<td align="center">'; echo '<a name="'.$filename.'" href="#'.$filename.'"><img src="'.$filename.'" /></a>'; echo 'bestand naam: ' . substr($filename,strlen($folder),strpos($filename, '.')-strlen($folder)); echo '</td>'; $ctr++; echo ($ctr % 4 == 0) ? "</tr>" : ""; } echo '</table>';
Comments
Post a Comment