Jump to content

Recommended Posts

greetings all,

 

I'm working on a page for a company that has multiple service locations and i'd like information to display a specific locations information depending on which city the user selects using a switch statement.

 

I'm new to php and have started to 'see the light' with switch statements (normally i would have done a bunch of if...elseif...else but i think this would keep the code a little cleaner).

 

anywho... I can't seem to find what i'm missing here... the page will not display anything except the default case... where am i going wrong?

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Untitled Document</title>
<meta name="keywords" content=""  />
<meta name="description" content="" />
<script type="text/JavaScript">
<!--
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>
</head>

<body onload="MM_preloadImages('images/glass-replacement/about-down.png','images/glass-replacement/specials-down.png','images/glass-replacement/locations-down.png','images/glass-replacement/services-down.png','images/glass-replacement/events-down.png','images/glass-replacement/contact-down.png')">
<div id="container">
<div id="header">
	<img src="images/auto-glass-new-england-header.gif"  />
</div>
		<div class="nav">>
			<div id="about"><a href="about-auto-glass-new-england.html" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image5','','images/glass-replacement/about-down.png',1)"><img src="images/glass-replacement/about-up.png" name="Image5" width="87" height="41" border="0" id="Image5" /></a></div>

			<div id="services"><a href="auto-glass-services.html" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image6','','images/glass-replacement/services-down.png',1)"><img src="images/glass-replacement/services-up.png" name="Image6" width="115" height="41" border="0" id="Image6" /></a></div>

			<div id="location"><a href="#" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image7','','images/glass-replacement/locations-down.png',1)"><img src="images/glass-replacement/locations-up.png" name="Image7" width="229" height="41" border="0" id="Image7" /></a></div>

			<div id="specials"><a href="auto-glass-specials.html" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image8','','images/glass-replacement/specials-down.png',1)"><img src="images/glass-replacement/specials-up.png" name="Image8" width="164" height="41" border="0" id="Image8" /></a></div>

			<div id="events"><a href="auto-glass-events.html" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image9','','images/glass-replacement/events-down.png',1)"><img src="images/glass-replacement/events-up.png" name="Image9" width="101" height="41" border="0" id="Image9" /></a></div>

			<div id="contact"><a href="auto-glass-new-england.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image10','','images/glass-replacement/contact-down.png',1)"><img src="images/glass-replacement/contact-up.png" name="Image10" width="103" height="41" border="0" id="Image10" /></a></div>
		</div>

	<div id="content-holder">
		<div id="content" class="bodycopy">
			<h1>Heading1</h1>
				<p>Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some Sex? Some text Some text Some text Some text Some text Some text Some text </p>
				<p>Toll Free at (XXX) XXX-XXXX</p>

		<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="GET" name="locations" onchange="document.locations.submit();">
			<select name="locationOption">
				<option>Select One...</option>
				<option>Location1</option>
				<option>Location2</option>
				<option>Location3</option>
				<option>Location4</option>
				<option>All Locations</option>
			</select>
		</form><br />
		</div>
	</div>
<?php 
switch ($_POST['locationOption']) {

case 'Location1':
	?>
		<div id="locationMap">
			<div align="center"><img src="" width="350" height="250"  /></div><br />
				<h2 align="center">Location1</h2>
				<p>Location information.....</p>						
		</div>

<div id="footer">
	<div align="center"><img src="" width="300" height="125" /></div>
		<p align="center" class="bottom">Footer text Footer text Footer text Footer text Footer text Footer text</p>
</div>				
</div>
</body>
</html>

<?php 
break;

case 'Location2':
	?>
		<div id="locationMap">
			<div align="center"><img src="" width="350" height="250"  /></div><br />
				<h2 align="center">Location2</h2>
				<p>Location information.....</p>					

		</div>

<div id="footer">
	<div align="center"><img src="" width="300" height="125" /></div>
		<p align="center" class="bottom">Footer text Footer text Footer text Footer text Footer text Footer text</p>
</div>				
</div>
</body>
</html>

<?php 
break;

case 'Location3':
	?>
		<div id="locationMap">
			<div align="center"><img src="" width="350" height="250"  /></div><br />
				<h2 align="center">Location3</h2>
				<p>Location information.....</p>					

		</div>

<div id="footer">
	<div align="center"><img src="" width="300" height="125" /></div>
		<p align="center" class="bottom">Footer text Footer text Footer text Footer text Footer text Footer text</p>
</div>					
</div>
</body>
</html>

<?php 
break;

case 'Location4':
	?>
		<div id="locationMap">
			<div align="center"><img src="" width="350" height="250"  /></div><br />
				<h2 align="center">Location4</h2>
				<p>Location information.....</p>					

		</div>

<div id="footer">
	<div align="center"><img src="" width="300" height="125" /></div>
		<p align="center" class="bottom">Footer text Footer text Footer text Footer text Footer text Footer text</p>
</div>					
</div>
</body>
</html>

<?php 
break;

case 'All Locations':
	?>
		<div id="locationMap">
			<div align="center"><img src="" width="350" height="250"  /></div><br />
				<h2 align="center">All Locations</h2>
				<p>Location information.....</p>	
		</div>

<div id="footer">
	<div align="center"><img src="" width="300" height="125" /></div>
		<p align="center" class="bottom">Footer text Footer text Footer text Footer text Footer text Footer text</p>
</div>				
</div>
</body>
</html>

<?php 
break;

default:
?>

<div id="footer">
	<div align="center"><img src="" width="300" height="125" /></div>
		<p align="center" class="bottom">Footer text Footer text Footer text Footer text Footer text Footer text</p>
</div>					
</div>
</body>
</html>
<?php
}
?>		

 

Link to comment
https://forums.phpfreaks.com/topic/144113-solved-becoming-a-switch-hitter-haha-jk/
Share on other sites

Man i am a huge noob... can't believe i've over looked that!!

 

thanks!

 

Question.... i was wanting to use the get method thinking that search engines would have an easier time indexing the different addresses and thus be able to add these locations to the various local searches... any thoughts on that?

Ooops, you don't have values for the options, you need:

 

               Select One...
               Location1
               Location2
               Location3
               Location4
               All Locations
            

 

I would recommend to change the last option value to just "all".  So change your case statement to:

 

   case 'all':

 

or else, because of the space, you would need to use URLencode.

I'll make this a separate post because I was writing it before you posted last.

 

For the GET method Instead of this:

 

         </pre>
<form action="<?php%20echo%20%24_SERVER%5B'PHP_SELF'%5D;%20?>" method="GET" name="locations" onchange="document.locations.submit();">
            
               Select One...
               Location1
               Location2
               Location3
               Location4
               All Locations
            
         <

 

do:

 

Location1
Location2
Location3
Location4
all

 

Change the switch statement to:

 

switch ($_GET['locationOption']) {

 

And because of the space you would have to do urlencode but it would be easier to change the value to:

 

   case 'all':

  • 1 month later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.