NYCPHP Meetup

NYPHP.org

[nycphp-talk] image display

Gary Mort bz-gmort at beezifies.com
Sun Aug 26 20:33:37 EDT 2007


selyah wrote:
> could someone please look at this code and please tell me what is wrong.
> it is suppose to display a 4 column table with an indiffenate number 
> of rows.
> Instead it displays one image in row , then 3 images in row 2.  Then 
> one image in row 3 and e images in row 4, and so on.  thanks.

Your end table code is in the wrong place.
Here is what your code is doing:
$col is set to 0

Your loop begins
Checks $col to see if it is 0, it is so it starts a row
Image 1
Checks $col to see if it is 0, it is so it ends the row
increments $col to 1
Checks $col to see if it is 4, it isn't so it does nothing.
Image 2
Checks $col to see if it is 0, it is not
increments $col to 2
Checks $col to see if it is 4, it isn't so it does nothing.
Image 3
Checks $col to see if it is 0, it is not
increments $col to 3
Checks $col to see if it is 4, it isn't so it does nothing.
Image 4
Checks $col to see if it is 0, it is not
increments $col to 4
Checks $col to see if it is 4, it is so it sets $col to 0
Checks $col to see if it is 0, it is so it starts a row
Image 5
Checks $col to see if it is 0, it is so it ends the row
....

Your output is probably really strange, as follows:
<Table>
<tr><td>image1</td></tr>
<td>image2</td><td>image3</td><td>image4</td>
<tr><td>image5</td></tr>
<td>image6</td><td>image7</td><td>image8</td>

Frankly, it's a matter of luck on how those non row cells get displayed.

Move if($col == 0)... to the end of the loop, after $col = ($col == 4) ? 
0 : $col; and you should be all good.




More information about the talk mailing list