Re: If statement duplicating mysql records?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Jason Pruim wrote:
Okay, so I have a question... Probably pretty easy, but why would my if statement show more records then what are in the database?

if($row[5] =='Level4'){ // White Highlight
            echo "<TR><TD bgcolor=".$Level4.">$row[0] </td>";
            echo "<td bgcolor=".$Level4.">$row[1]  </td>";
echo "<td bgcolor=".$Level4."><A href ='$row[2]'>Instructions</A></td>"; echo "<TD bgcolor=".$Level4."><A href='update.php?taskid=$row[0]'>Click here!</A>";
        }// End of Level 4
else {// Green Highlight
            echo "<TR><TD bgcolor=".$unclassified.">$row[0] </td>";
            echo "<td bgcolor=".$unclassified.">$row[1]  </td>";
echo "<td bgcolor=".$unclassified."><A href ='$row[2]'>Instructions</A></td>"; echo "<TD bgcolor=".$unclassified."><A href='update.php?taskid=$row[0]'>Click here!</A>"; }// End of Unclassified


Why not do it this way instead.

while( $row = mysql_fetch_array($results) ) {

	$rowColor = $unclassified;

	// White Highlight
	if($row[5] =='Level4'){
		$rowColor = $Level4;
	}

	echo "<TR><TD bgcolor=".$rowColor.">$row[0] </td>";
	echo "<td bgcolor=".$rowColor.">$row[1]  </td>";
	echo "<td bgcolor=".$rowColor."><A href='$row[2]'>Instructions</A></td>";
	echo "<TD bgcolor=".$rowColor."><A href='update.php?taskid=$row[0]'>Click here!</A>";

}



If I have a record that matches Level4 it will display both with the $Level4 color and the $unclassified color. Ideally it would only show up under the $Level4 category if it's Level4... If that makes sense.

Or is there a better way to do it?

Thanks! :)

And one of these days, I WILL be able to help answer questions on this list too! :)

--PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



--
Jim Lucas

   "Some men are born to greatness, some achieve greatness,
       and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
    by William Shakespeare

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux