Be a Supporter!

Array question

  • 277 Views
  • 3 Replies
New Topic Respond to this Topic
AntiTanner
AntiTanner
  • Member since: Nov. 26, 2000
  • Offline.
Forum Stats
Member
Level 32
Blank Slate
Array question 2001-11-19 09:51:45 Reply

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.
Forum Stats
Staff
Level 28
Blank Slate
Response to Array question 2001-11-19 12:50:27 Reply

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.
Forum Stats
Member
Level 32
Blank Slate
Response to Array question 2001-11-19 13:45:17 Reply

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.
Forum Stats
Staff
Level 28
Blank Slate
Response to Array question 2001-11-20 18:32:02 Reply

At 11/19/01 01:45 PM, TannerCenterwall wrote: Worked like a charm.

Sccchweet. Looks good. Glad you got it working ok ;)