Array question
- AntiTanner
-
AntiTanner
- Member since: Nov. 26, 2000
- Offline.
-
- Send Private Message
- Browse All Posts (16,610)
- Block
-
- Forum Stats
- Member
- Level 32
- Blank Slate
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.
- liljim
-
liljim
- Member since: Dec. 16, 1999
- Offline.
-
- Send Private Message
- Browse All Posts (11,644)
- Block
-
- Forum Stats
- Staff
- Level 28
- Blank Slate
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++;
}
- AntiTanner
-
AntiTanner
- Member since: Nov. 26, 2000
- Offline.
-
- Send Private Message
- Browse All Posts (16,610)
- Block
-
- Forum Stats
- Member
- Level 32
- Blank Slate
At 11/19/01 12:50 PM, liljim wrote: .... 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++;
}
Worked like a charm. I knew i could count on ya jim! Many thanks.
- liljim
-
liljim
- Member since: Dec. 16, 1999
- Offline.
-
- Send Private Message
- Browse All Posts (11,644)
- Block
-
- Forum Stats
- Staff
- Level 28
- Blank Slate
At 11/19/01 01:45 PM, TannerCenterwall wrote: Worked like a charm.
Sccchweet. Looks good. Glad you got it working ok ;)

