vForums Support > Programming & Coding :: Programming Discussion :: > Alternation rows in a mysql query

Alternation rows in a mysql query - Posted By Dylan (dylan) on 2nd Mar 08 at 8:05pm
Ok I'm looping through some data and displaying each row from the mysql table and displaying it in a table.

My question is I want to alternate between class1 and class2 when looping through the tables.

How would I do that?

Re: Alternation rows in a mysql query - Posted By Marc (cr0w) on 2nd Mar 08 at 8:11pm
Code:
 
  1. $n = 1;
  2. while(mysql_fetch_assoc($query)){
  3.  
  4. //Stuff here
  5. echo '<td class="class' . $n .'">';
  6.  
  7. if($n==1) $n = 2; else $n = 1;
  8. }
 

Re: Alternation rows in a mysql query - Posted By Dylan (dylan) on 2nd Mar 08 at 8:27pm
Shouldn't it be adding a number to?

EDIT :
Thanks cr0w it works {Smile}

Re: Alternation rows in a mysql query - Posted By Marc (cr0w) on 2nd Mar 08 at 8:31pm
 
Shouldn't it be adding a number to?

EDIT :
Thanks cr0w it works {Smile}


No problem. {Smile}