Re: Modulus Formatting
| From: | Web Admin | Date: | Tue, 06 Feb 2001 13:24:03 +0000 |
| Subject: | Re: Modulus Formatting | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-38382@lists.php.net to get a copy of this message | ||
Hi Michael,
Use a temporary variable [counter], if counter%3 == 0 then
write </tr><tr> in the output.
$counter=0; print "<tr>";
while($row = mysql_fetch_array($result)) {
echo "<td>".$row["user_id"]."</td>"; $counter++;
if (!$counter%3) { echo "</tr><tr>"; }
}
That's all ;-)
Ahmad Anvari
----- Original Message -----
From: Michael Hall
To: PHP List
Sent: Tuesday, February 06, 2001 10:03 AM
Subject: [PHP] Modulus Formatting
> I can pull data out of a database using mysql_fetch_array and assemble
it like this using a while statement:
>
> <TR><TD>$data</TD></TR>
> <TR><TD>$data</TD></TR>
> <TR><TD>$data</TD></TR>
> etc ...
>
> What I'd like to do is assemble it like this:
>
>
> <TR><TD>$data</TD><TD>$data</TD><TD>$data</TD></TR>
> etc...
>
> In other words, I need a break (</TR><TR>) every three times through the
> loop.
>
> I've tried several snippets of code from this list's archive but none seem
> to work. I've tried while statements, for statements and the list function
> in every combination I can think of ... no go. I know that modulus is
what I need but I can't crack the right code combination.
>
> Does anyone have a solution or can they point me to a resource somewhere?
>
>
> Thanks
>
> Mick
>
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
For additional commands, e-mail: php-general-help@lists.php.net
To contact the list administrators, e-mail: php-list-admin@lists.php.net