Displaying Images in a Table

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tambourine
Forum Newbie
Posts: 2
Joined: Wed Feb 15, 2006 6:50 am
Location: Scotland

Displaying Images in a Table

Post by tambourine »

Hello, im new to php and i have failed to work out how to display images in a table that consist of 5 rows by 5 columns.

I think a IF loop is needed, but i couldn't seem to any to work :cry:

The variable im trying to displays is

Code: Select all

<?php echo $row_blobby['previewpath']; ?>
Im basically trying to get my images to display in a 5 * 5 table.

Hope, someone can help or guide me in the correct direction. Thanks! :D
User avatar
AndrewBacca
Forum Commoner
Posts: 62
Joined: Thu Jan 30, 2003 10:03 am
Location: Isle of Wight, UK

Post by AndrewBacca »

this is untested but give it ago

Code: Select all

<?php
print "<table>";
for ($i = 0; $i <= 5; $i++) {
     if ($i % 5 == 0) {
         print "<tr>"; 
    }

     print "<td>" . $row_blobby['previewpath'] . "</td>";

     if ($i % 5 == 5) {
         print "</tr>";
    }
}
print "</table>";
?>
hope that helps/works
tambourine
Forum Newbie
Posts: 2
Joined: Wed Feb 15, 2006 6:50 am
Location: Scotland

Post by tambourine »

Ok, this code works kinda....

Code: Select all

<?php
print "<table>"; 
for ($i = 0; $i <= 5; $i++) { 
     if ($i % 5 == 0) { 
         print "<tr>"; 
    } 

     print '<td><img src="http://'.$row_blobby['previewpath'].'" /></td>'; 

     if ($i % 5 == 5) { 
         print "</tr>"; 
    } 
} 
print "</table>"; 
?>
....it displays the same image 5 times accross and 1 time down

Exmaple: http://www.surgeryofsound.co.uk/mobile- ... all-uk.php

Any more suggestions?

Thank you!
User avatar
AndrewBacca
Forum Commoner
Posts: 62
Joined: Thu Jan 30, 2003 10:03 am
Location: Isle of Wight, UK

Post by AndrewBacca »

I think this should work

Code: Select all

<?php
print "<table>"; 
for ($i = 0; $i <= 4; $i++) { 
     if ($i % 5 == 0) { 
         print "<tr>"; 
    } 

     print '<td><img src="http://'.$row_blobby['previewpath'].'" /></td>'; 

     if ($i % 5 == 5) { 
         print "</tr>"; 
    } 
} 
print "</table>"; 
?>
Post Reply