i have a folder of jpg images and i would like to put them into a table of 4images wide without using mySQL. would it be possible to count them and then divid the number by 4 and insert a seperate table for each row of 4.
If theres a more efficient way please tell me.
Andy
projecting images in a folder into a table [solved]
Moderator: General Moderators
-
andylyon87
- Forum Contributor
- Posts: 168
- Joined: Sat Jan 31, 2004 5:31 am
- Location: Dundee
projecting images in a folder into a table [solved]
Last edited by andylyon87 on Sun Jun 19, 2005 3:40 pm, edited 1 time in total.
Code: Select all
print('<table>');
$dir = opendir('images/');
$cols = 0;
while ($file = readdir($dir)) {
if (!$cols) print('<tr>');
print("<img src='{$file}' alt='{$file}' />");
if ($cols > 3) { // adjust this number to change the number columns.
print('</tr>');
$cols = 0;
}
else $cols++;
}
print('</table>');-
andylyon87
- Forum Contributor
- Posts: 168
- Joined: Sat Jan 31, 2004 5:31 am
- Location: Dundee
-
andylyon87
- Forum Contributor
- Posts: 168
- Joined: Sat Jan 31, 2004 5:31 am
- Location: Dundee
-
andylyon87
- Forum Contributor
- Posts: 168
- Joined: Sat Jan 31, 2004 5:31 am
- Location: Dundee
fixed it
Code: Select all
<?print('<TABLE cellpadding=0 cellspacing=4 border=0 width=760>');
$dir = opendir("$id/");
$cols = 0;
while ($file = readdir($dir)) {
if (!$cols){ print('<tr>');}
if(is_file("$id/$file")){
list($width, $height)=getimagesize("$id/$file");
if($height<$width){
print("<TD><img src=$id/$file alt=$file width=120></TD>");
}
if($height>=$width){
print("<TD><img src=$id/$file alt=$file width=80></TD>");
}
if ($cols > 2) {
print('</tr>');
$cols = 0;
}else{
$cols++;
}}
}
print('</table>');
?>