At 11/19/01 09:51 AM, TannerCenterwall wrote:
Allright, im pulling info out of a database using a "while" loop, but every 2nd time it loops i need to do something extra. Its going to be a table basically like:
tr
td td
tr
td td
so every other time the loops runs, i need to print (/tr)(tr). This is prolly real simple, but its been bugging me.
Hmmm... Wouldn't this do it?
while($row = mysql_fetch_array($query)) {
$field1 = $row['Field1'];
$field2 = $row['Field2'];
echo "<tr>n";
echo "<td>$field1</td>n";
echo "<td>$field2</td>n";
echo "</tr>n";
}
.... or am I misunderstanding something? I suppose you could use the modulo (%) as an alternative...
$x = 1;
while($row = //do whatever) {
// Whatever
if (($x % 2) == 0) {
// do something, cos it's a division of 2.
}
$x++;
}