Zen Cart Logo
Forums / Templates, Stylesheets, Page Layout / Need Help With If Statement For Displaying Images

Need Help With If Statement For Displaying Images

Locked

Views: 1,084

Results 1 to 2 of 2
This thread is locked. New replies are disabled.
6 Apr 2010, 9:08 PM
#1
games4gamers avatar

games4gamers

New Zenner

Join Date:
Dec 2008
Posts:
55
Plugin Contributions:
0

Need Help With If Statement For Displaying Images

I am trying to come up with a way to display an image based on the value of a field in the database for each product. For example if the field's value is E, it would display the image for E. If the value was T, it would display the image for T, and so forth. Here is what I have so far code-wise:

<?php /*
	if ($_GET['esrb_rating'] == "EC") 
		{
			echo '<img src="/esrb/ec_esrb.jpg" width="122" height="88" alt="Early Childhood ESRB Rating">';
		}
	else {
		if ($_GET['esrb_rating'] == "E") 
		{
			echo '<img src="/esrb/e_esrb.jpg" width="122" height="88" alt="Everyone ESRB Rating">';
		
		}
	}
	else {
		if ($_GET['esrb_rating'] == "E10+") 
		{
		
			echo '<img src="/esrb/e10_esrb.jpg" width="122" height="88" alt="Everyone 10+ ESRB Rating">';
		
		}
	}
	else {
		if ($_GET['esrb_rating'] == "T") 
		{
		
			echo '<img src="/esrb/t_esrb.jpg" width="122" height="88" alt="Teen ESRB Rating">';
		
		}
	}
	else {
		if ($_GET['esrb_rating'] == "M") 
		{
		
			echo '<img src="/esrb/m_esrb.jpg" width="122" height="88" alt="Mature ESRB Rating">';
		
		}
	}
	else {
		if ($_GET['esrb_rating'] == "AO") 
		{
		
			echo '<img src="/esrb/ao_esrb.jpg" width="122" height="88" alt="Adults Only ESRB Rating">';
		
		}
	}
	else {
	if ($_GET['esrb_rating'] == "RP") 
		{
		
			echo '<img src="/esrb/rp_esrb.jpg" width="122" height="88" alt="Rating Pending ESRB Rating">';
		
		}
	}	
	else {
	}*/
	?>

I have no idea if I even coded this correctly. I borrowed the idea from someone else, so not sure if I'm doing it correctly or not. Thanks for any help.

7 Apr 2010, 6:29 PM
#2
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Need Help With If Statement For Displaying Images

Try using:

	switch($_GET['esrb_rating']) {
	  case 'EC':
      echo '<img src="/esrb/ec_esrb.jpg" width="122" height="88" alt="Early Childhood ESRB Rating">';
      break;
	  case 'E':
			echo '<img src="/esrb/e_esrb.jpg" width="122" height="88" alt="Everyone ESRB Rating">';
      break;
	  case 'E10+':
			echo '<img src="/esrb/e10_esrb.jpg" width="122" height="88" alt="Everyone 10+ ESRB Rating">';
      break;
    case 'T':
			echo '<img src="/esrb/t_esrb.jpg" width="122" height="88" alt="Teen ESRB Rating">';
      break;
    case 'M':
			echo '<img src="/esrb/m_esrb.jpg" width="122" height="88" alt="Mature ESRB Rating">';
      break;
    case 'AO':
			echo '<img src="/esrb/ao_esrb.jpg" width="122" height="88" alt="Adults Only ESRB Rating">';
      break;
    case 'RP':
			echo '<img src="/esrb/rp_esrb.jpg" width="122" height="88" alt="Rating Pending ESRB Rating">';
      break;
   }