Jump to content

[SOLVED] Can you help me please


cdog1912

Recommended Posts

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  :)

Link to comment
https://forums.phpfreaks.com/topic/137124-solved-can-you-help-me-please/
Share on other sites

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>";
?>

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>';
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.