Hello everyone,

I have a code to display images in a table for a specific ticket. I am needing the table to be 4 columns wide then repeat until there is no more images to show.

Here is my code:

<?php
$folder = "images/ticket_images/".$_REQUEST['ticketid']."/";
$filetype = '*.*';
$files = glob($folder.$filetype);
echo '<table><tr>';
for ($i=0; $i<count($files); $i++) {
    echo '<td>';
    echo '<a name="'.$files[$i].'" href="'.$files[$i].'"><img width="100" height="100" src="'.$files[$i].'" /></a>';

    echo '</td>';
}
echo '</tr></table>';
?>

Any help would be great.

Thanks,
Patrick

I tried this, but its not working.

    <?php
    $col =0
    $folder = "images/ticket_images/".$_REQUEST['ticketid']."/";
    $filetype = '*.*';
    $files = glob($folder.$filetype);
    echo '<table><tr>';
    for ($i=0; $i<count($files); $i++) {
    $col++
    echo '<td>';
    echo '<a name="'.$files[$i].'" href="'.$files[$i].'"><img width="100" height="100" src="'.$files[$i].'" /></a>';
    echo '</td>';
    if($col % 4) print '</tr><tr>';
    }else{

    echo '</tr></table>';
    }
    ?>

I made a code snippet about this a while back. You can find it under the PHP code snippets tab.

I think i got it now.

<table width="100%" cellpadding="5" cellspacing="5"><tr>
              <?php
$cols=4;              
$folder = "images/ticket_images/".$_REQUEST['ticketid']."/";
$filetype = '*.*';
$files = glob($folder.$filetype);

for ($i=0; $i<count($files); $i++) {
$cols++;
    echo '<td align="center">';
    echo '<a name="'.$files[$i].'" href="'.$files[$i].'"><img width="100" height="100" src="'.$files[$i].'" /></a><br><span style=" font-size:8px; color:#339;"><a href="ticketdetails.php?ticketid='.$_REQUEST['ticketid'].'&amp;removepic=1&filename='.substr($files[$i],strlen($folder),strpos($files[$i], '.')-strlen($folder)).'.'.end(explode('.', $files[$i])).'">Delete</a></span>';
    echo '</td>';
    if ($cols % 4 == 0) {
        echo '</tr><tr>';
}
}
?>
</tr></table>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.