Loop does not work as expected

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
auaero
Forum Newbie
Posts: 9
Joined: Wed Aug 28, 2002 9:47 am

Loop does not work as expected

Post 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
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post 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!
User avatar
auaero
Forum Newbie
Posts: 9
Joined: Wed Aug 28, 2002 9:47 am

Found the problem

Post by auaero »

Thanks Gen... I didn't have the case right. *duh* :oops:
Post Reply