Page 1 of 1

Loop does not work as expected

Posted: Tue Oct 01, 2002 3:56 pm
by auaero
Hi guys, I was hoping someone could take a look at this and point out the problem (if there is one... )

I'm writing a little web app to display the top ten viruses as reported by Trend Micro. I want to have a small color coded icon appear next to each virus to represent it's risk factor (gray = low, yellow = medium, red = high). Each virus's risk factor is stored in an array callled $risk. I want the loop to assign the appropriate icon for the risk factor. However, the loop always returns blank.gif for the icon. The only time blank.gif should be returned is if there is no risk factor recorded for the virus. Here's the code:

Code: Select all

<?php
	$j = 0;
	while ($j <= 9) {
		if ($riskї$j] == "low") {
			$statusї$j] = "images/gray.gif";
		} elseif ($riskї$j] == "medium") {
			$statusї$j] = "images/yellow.gif";
		} elseif ($riskї$j] == "high") {
			$statusї$j] = "images/red.gif";
		} else {
			$statusї$j] = "images/blank.gif";
		} 
		$j++;	
	}

?>
Does anyone see any reason this won't work? I can't see it, but I'm fairly new to PHP, so it's entirely possible I just overlooked something.

Thank in advance,
AUaero

Posted: Tue Oct 01, 2002 4:08 pm
by Gen-ik
I've changed your code a small bit..

Code: Select all

<?php

   $j = 0; 
   while ($j < 10) { 
      if ($riskї$j] == "low")
      { 
      $statusї$j] = "images/gray.gif"; 
      }
      else if ($riskї$j] == "medium")
      { 
      $statusї$j] = "images/yellow.gif"; 
      }
      else if ($riskї$j] == "high")
      { 
      $statusї$j] = "images/red.gif"; 
      }
      else
      { 
      $statusї$j] = "images/blank.gif"; 
      }  
      $j++;    
   } 

?>

..i haven't tested it so you will have to do that.

Also.. make sure that the $risk array variables are set properly, for example..

$risk[0]="low" and not $risk[0]="Low" or $risk[0]="LOW"

..as PHP seems to be very case sensitive.

Hope this helps!

Found the problem

Posted: Tue Oct 01, 2002 4:17 pm
by auaero
Thanks Gen... I didn't have the case right. *duh* :oops: