Hi all,
I'm trying to work out how to make it so I can have 5 cells per line in a table, with the results slotting in. Then when five are filled up, a new row is started.
Please could anyone help?
Thanks,
Mike
Hi all,
I'm trying to work out how to make it so I can have 5 cells per line in a table, with the results slotting in. Then when five are filled up, a new row is started.
Please could anyone help?
Thanks,
Mike
Don't you just love free internet games ?
You mean, display the results of a query in columns?
So it'd be:
result 1 - result 2 - result 3 - result 4 - result 5
result 6 - result 7
etc?
Stepping On Wires - the new blog
Exactly Mark
Don't you just love free internet games ?
Put in a counter where each time a cell is added, the counter is incremented by 1. When it gets to 5, start a new row.
Conceptually it would look something like this (adapt this for ASP/PHP/whatever):
i = 0
<tr>
begin loop
if i = 5 then
</tr><tr>
i = 0 (reset counter)
end if
<td>result</td>
i = i + 1
end loop
</tr>
That'll be it, thanks Paul
Don't you just love free internet games ?
I like to do it with division.
If I was making a table and I wanted it to print out 3 cells to a row all you need to do is put the following code at the end of the loop.
if(!($i % 3)){
echo "</tr><tr>";
}
For 4 cells to a row change the 3 to a 4, etc.
Seems easier...
So do you put that when the main loop has finished, or actually inside the loop? Also, could you tell me what the % on the first line does please?
Thanks a lot,
Mike
Don't you just love free internet games ?
The % is the modulus operator.
$i is the counter variable, you still need to increment it ($i++) at the bottom.
The modulus operator returns the remainder from division. So it returns the remainder of $i/3. If there is no remainder, then 3 is a factor of $i, hence its time to start a new row.
Check out this article for more in php operators.
http://www.developer.com/lang/php/article.php/938511
Oddly enough it was written by the woman who did the design for WebsitePublisher.
Heh, thanks Chris
Don't you just love free internet games ?
I tried it out today, and it kinda worked. Only problem was that it had the first emotion on a seperate line to the rest. To get what I mean, look: http://www.msn-emotions.net/downloads/animal-emotions
My code is as follows:
Please could someone help?PHP Code:
for ($y=0; $y < mysql_num_rows($result2); $y++) {
$row2 = mysql_fetch_assoc($result2);
echo ("<td width=10%>");
echo ("<img src='");
echo $row2['URL'];
echo ("'></td>");
if(!($y % 5)){
echo "</tr><tr>";
}
}
Thanks a lot,
Mike
Don't you just love free internet games ?
Perhaps start $y at 1, because at zero it's not doing what you want.
for ($y=1; $y <= mysql_num_rows($result2); $y++) {
....
Yep, that's done it. Thanks guys
Don't you just love free internet games ?
Bookmarks