$what=y; while($array=mysql_fetch_array($query)){ if($what==y){ echo "x"; } if($waht==x} echo "y"; } if($what==y){ $what=x; } else { $what=y; } }