PDA

View Full Version : PHP Table help


HexOnxOnx
Mon 27th Dec '04, 8:38pm
Hi all

Below is some code that I need help with. It is not vB related but is for a photo site. The code displays a members photos on a table with only one column. Each photo is displayed in it's own row in that one column so each photo appears below the previous like this:

photo
photo
photo
photo

This makes the page rather long if someone has alot of photos.


I would like to change this code so that there are two columns so that it would look like this

photo photo
photo photo
photo photo

below is the code, it's not that hard to figure out, I just have no clue to do what I want above.


$imgdir=strtolower("photo/$profil[nick]");
if(is_dir($imgdir)) $timgs=ReadThumbImages($profil["nick"]);
if(is_array($timgs)) {
$viewImgs = "<table border='0' cellpadding='0' cellspacing='0' bgcolor='#CCCCCC'>
<tr>
<td>
<table width='100%' border='0' cellspacing='1' cellpadding='4'>";
foreach($timgs as $timg) {
$imgNrs++;
$viewImgs .= "<tr bgcolor='#FFFFFF'>"; $i++;
$viewImgs .= "<td align='center'><a href=\"JavaScript: gow('$imgdir/b_".substr($timg,2,strlen($timg))."')\"><img src='$imgdir/$timg' alt='$timg' border=0></a></td>";

$viewImgs .= "</tr>"; //$i=0;}
}

$viewImgs .= "</table>
</td>
</tr>
</table>";
}
}



Thanks for any help!

Icheb
Mon 27th Dec '04, 9:44pm
$i = 1;
while (do whatever you want) {
if ($i % 2 != 0) {
// display content in left column
}
else {
// display content in right column
}
$i++;
}


That would display your photos in the order of

1 2
3 4
5 6
7 8

Having it in

1 5
2 6
3 7
4 8

is certainly also possible and not much harder.

HexOnxOnx
Mon 27th Dec '04, 10:50pm
Thanks but how would I put that in my code above? I am lost here!

Icheb
Tue 28th Dec '04, 2:09pm
Put it in your foreach().

HexOnxOnx
Tue 28th Dec '04, 10:55pm
Well thanks anyways. What I needed was for someone to alter the code for me because I have no clue on what to do. I didn't write the code. I just know enough to know that code controls the images. I have no idea how to even insert it in the foreach() part.

Icheb
Tue 28th Dec '04, 11:10pm
Try this.

$imgdir=strtolower("photo/$profil[nick]");
if(is_dir($imgdir)) $timgs=ReadThumbImages($profil["nick"]);
if(is_array($timgs)) {
$viewImgs = "<table border='0' cellpadding='0' cellspacing='0' bgcolor='#CCCCCC'>
<tr>
<td>
<table width='100%' border='0' cellspacing='1' cellpadding='4'>";
$counter = 1;
foreach($timgs as $timg) {
$imgNrs++;
if ($counter % 2 != 0) {
$viewImgs .= "<tr bgcolor='#FFFFFF'>"; $i++;
$viewImgs .= "<td align='center'><a href=\"javascript: gow('$imgdir/b_".substr($timg,2,strlen($timg))."')\"><img src='$imgdir/$timg' alt='$timg' border=0></a></td>";
}
else {
$i++;
$viewImgs .= "<td align='center'><a href=\"javascript: gow('$imgdir/b_".substr($timg,2,strlen($timg))."')\"><img src='$imgdir/$timg' alt='$timg' border=0></a></td>";

$viewImgs .= "</tr>"; //$i=0;}
}
$counter++;
}

$viewImgs .= "</table>
</td>
</tr>
</table>";
}
}

HexOnxOnx
Tue 28th Dec '04, 11:22pm
That still displays the photos in one long column.

Icheb
Tue 28th Dec '04, 11:29pm
I corrected a small mistake in the above code. Please try again.

HexOnxOnx
Tue 28th Dec '04, 11:31pm
I corrected a small mistake in the above code. Please try again.

That worked!!! Thanks very much for the help and for being patient! ;)