00:00
00:00
Newgrounds Background Image Theme

picapip just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

Array question

613 Views | 3 Replies
New Topic Respond to this Topic

Array question 2001-11-19 09:51:45


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.

Response to Array question 2001-11-19 12:50:27


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++;
}

Response to Array question 2001-11-19 13:45:17


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.

Response to Array question 2001-11-20 18:32:02


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

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