Same content repeating in rows instead of just once

In my while statement, I have twelve <td> HTML table cells, one for each month. I test the array content to make sure the data in the month cell of the DB matches the month cell in the HTML table. If it matches, it goes into that table cell.

However, it’s repeating the content across all 12 cells, then giving me the next month’s data across another twelve cells, etc.

Why aren’t my IF statements filtering the data properly? Why is it repeating across all 12 HTML table cells?


while ($sqlarray = mysql_fetch_array($sql)) {
    $tier_level1_item = htmlspecialchars($sqlarray['tier_level1_item']); 
    $tier_level1_brand = htmlspecialchars($sqlarray['tier_level1_brand']); 
    $tier_level2_item = htmlspecialchars($sqlarray['tier_level2_item']); 
    $tier_level2_brand = htmlspecialchars($sqlarray['tier_level2_brand']); 
    $tier_level3_item = htmlspecialchars($sqlarray['tier_level3_item']); 
    $tier_level3_brand = htmlspecialchars($sqlarray['tier_level3_brand']); 
    $mag_name = htmlspecialchars($sqlarray['mag_name']); 
    $mag_month = htmlspecialchars($sqlarray['mag_month']); 
    $mag_year = htmlspecialchars($sqlarray['mag_year']); 
	
/* For months for which no magazine has been entered, enter -- */	
	if (strlen($tier_level1_item) < 1){ $tier_level1_item = '--'; }
	if (strlen($tier_level1_brand) < 1){ $tier_level1_brand = '--'; }
	if (strlen($tier_level2_item) < 1){ $tier_level2_item = '--'; }
	if (strlen($tier_level2_brand) < 1){ $tier_level2_brand = '--'; }
	if (strlen($tier_level3_item) < 1){ $tier_level3_item = '--'; }
	if (strlen($tier_level3_brand) < 1){ $tier_level3_brand = '--'; }
	?>

		<td class="row1"><?php
if ($mag_name = 'Action') {
	if ($mag_year = '2010') {
		if ($mag_month = '01 Jan') {
		echo"<p><strong>T1: " . $tier_level1_item . "</strong><br>";
		echo "T1: " . $tier_level1_brand . "<br>";
		echo "<strong>T2: " . $tier_level2_item . "</strong><br>";
		echo "T1: " . $tier_level2_brand . "<br>";
		echo "<strong>T1: " . $tier_level3_item . "</strong><br>";
		echo "T1: " . $tier_level3_brand . "</p></td>";
}}}
	?>
		<td class="row2"><?php
if ($mag_name = 'Action') {
	if ($mag_year = '2010') {
		if ($mag_month = '02 Feb') {
		echo"<p><strong>T1: " . $tier_level1_item . "</strong><br>";
		echo"T1: " . $tier_level1_brand . "<br>";
		echo"<strong>T2: " . $tier_level2_item . "</strong><br>";
		echo"T1: " . $tier_level2_brand . "<br>";
		echo"<strong>T1: " . $tier_level3_item . "</strong><br>";
		echo"T1: " . $tier_level3_brand . "</p></td>";
}}}
	?>
... ten more times...

Thanks!
Steve

I made it work:

$cell = 1;
while ($sqlarray = mysql_fetch_array($sql)) {
    $tier_level1_item = htmlspecialchars($sqlarray['tier_level1_item']); 
    $tier_level1_brand = htmlspecialchars($sqlarray['tier_level1_brand']); 
    $tier_level2_item = htmlspecialchars($sqlarray['tier_level2_item']); 
    $tier_level2_brand = htmlspecialchars($sqlarray['tier_level2_brand']); 
    $tier_level3_item = htmlspecialchars($sqlarray['tier_level3_item']); 
    $tier_level3_brand = htmlspecialchars($sqlarray['tier_level3_brand']); 
    $mag_name = htmlspecialchars($sqlarray['mag_name']); 
    $mag_month = htmlspecialchars($sqlarray['mag_month']); 
    $mag_year = htmlspecialchars($sqlarray['mag_year']); 
	
	
/* For months for which no magazine has been entered, enter -- */	
	if (strlen($tier_level1_item) < 1){ $tier_level1_item = '--'; }
	if (strlen($tier_level1_brand) < 1){ $tier_level1_brand = '--'; }
	if (strlen($tier_level2_item) < 1){ $tier_level2_item = '--'; }
	if (strlen($tier_level2_brand) < 1){ $tier_level2_brand = '--'; }
	if (strlen($tier_level3_item) < 1){ $tier_level3_item = '--'; }
	if (strlen($tier_level3_brand) < 1){ $tier_level3_brand = '--'; }

	if ($cell == 1) {$cellmonth = '01 Jan' ;}
	if ($cell == 2) {$cellmonth = '02 Feb' ;}
	if ($cell == 3) {$cellmonth = '03 Mar' ;}
	if ($cell == 4) {$cellmonth = '04 Apr' ;}
	if ($cell == 5) {$cellmonth = '05 May' ;}
	if ($cell == 6) {$cellmonth = '06 Jun' ;}
	if ($cell == 7) {$cellmonth = '07 Jul' ;}
	if ($cell == 8) {$cellmonth = '08 Aug' ;}
	if ($cell == 9) {$cellmonth = '09 Sep' ;}
	if ($cell == 10) {$cellmonth = '10 Oct' ;}
	if ($cell == 11) {$cellmonth = '11 Nov' ;}
	if ($cell == 12) {$cellmonth = '12 Dec' ;}
	

		echo"<td class='row1'>";
		if ($mag_month == $cellmonth) {
		echo"<p><strong>T1: " . $tier_level1_item . "</strong><br>";
		echo "T1: " . $tier_level1_brand . "<br>";
		echo "<strong>T2: " . $tier_level2_item . "</strong><br>";
		echo "T1: " . $tier_level2_brand . "<br>";
		echo "<strong>T1: " . $tier_level3_item . "</strong><br>";
		echo "T1: " . $tier_level3_brand . "</p></td>";
		}
if ($cell < 12) {$cell++;}
else { echo "</tr></tbody></table>"; }
} // WHILE end bracket
?>