Re: looping
| From: | Ignacio Vazquez-Abrams | Date: | Mon, 15 Jan 2001 21:22:06 +0000 |
| Subject: | Re: looping | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-34678@lists.php.net to get a copy of this message | ||
On Mon, 15 Jan 2001, Jerry Lake wrote:
> excuse my density today
> my brain is still in weekend mode
>
> how would I make this loop put 4 or 5 items (haven't decided)
> per line instead of just one item and the checkbox on each line?
>
> <snip>
> echo "<table border='1' cellpadding='2'
> cellspacing='2'>";
>
> while($myrow = mysql_fetch_array($result2))
> {
> $name = $myrow["name"];
> $personal_cost = $myrow["personal_cost"];
> $small_cost = $myrow["small_cost"];
> $large_cost = $myrow["large_cost"];
> $category = $myrow["category"];
>
> echo "<tr>";
> echo "<td>";
> echo $name;
> echo "</td>";
> echo "<td><input type=checkbox name=topping
> value=".$cost.">".$cost."</td>";
> echo "</tr>";
> }
> echo "</table>";
> </snip>
>
> Jerry Lake
>
Join the club :)
<?php
define('PERLINE', 4); // or 5, depending on taste
...
echo "<table border='1' cellpadding='2'
cellspacing='2'>";
echo "<tr>";
$i=0;
$numrows=mysql_num_rows($result2);
while($myrow = mysql_fetch_array($result2))
{
++$i;
...
echo "<td>";
...
echo "</td>";
if (!($i%PERLINE) and ($numrows!=$i))
{
echo("</tr><tr>");
};
};
echo "</tr>";
echo "</table>";
?>
--
Ignacio Vazquez-Abrams <ignacio@openservices.net>