Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...This site is like first coffee in the winter morning..."

Geography

Where in the world do Tek-Tips members come from?
tekpr00 (IS/IT--Management)
24 Oct 11 17:28
Hello All,
Thanks for everyone that has been helping me with this PHP becuase I am just learning it. Lets face it I am not much of a coder.lol
My next problem is that I am trying to use switch to print array however when I use the query from the drop down list to print the array nothing shows. Here is my result and code below. Thanks for your input as usual

Result
Office: (Pick one)

(Query)
Nothing shows

CODE

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
 <head>
  <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
  
  <title> Employee Office Array </title>
  
 </head>
 <body>

<form action="emp_office_array.php" method="post">
<p>Office:
<select name ="office">
<option value="">Pick One</option>
<option value="foyer">Foyer</option>
<option value="common">Common</option>
<option value="north">North</option>
<option value="south">South</option>
</select></p>

<input type="submit" name="submit"
 value="Query" />

<?php
//Create first array:
$foyer = array(0=> "1. John Smith");

//create second array:
$common = array(0=> "1. Fred Flintstone" , "2. Ann Jones");

//create third array:
$north = array(0=> "1. Pebbles Flintstone", "2. Dino Flintstone");

//create fourth array:
$south = array(0=> "1. Betty Rubble", "2. Barney Rubble", "3. Great Gazoo");

//creat associtive array:
$offices = array (
'Foyer' => $foyer,
'Common' => $common,
'North' => $north,
'South' => $south
);

//print contents

//var_dump($offices);
$offices=$_POST['offices'];
switch ($offices){
    case 'Foyer':
    print "<p>Employee in $foyer is</p>";
    print "<p><i>{$offices['foyer'][0]}</i>.</p>";
    break;
    case 'common':
    print "<p> Employee in $common are</p>";
    print "<p><i>{$offices['Common'][0][1]}</i>.</p>";
    break;
    print "<p> Employee in $north are</p>";
    print "<p><i>{$offices['North'][0][1]}</i>.</p>";
    break;
    print "<p> Employee in $south are</p>";
    print "<p><i>{$offices['South'][0][1][2]}</i>.</p>";
    break;
}//end of switch

?>
 </form>
</body>
</html>
vacunita (Programmer)
24 Oct 11 19:25
There's a few errors there which should be showing up.

However the main issue seems to be that you are overwriting your array so it is no longer an array, but a string.

CODE

$offices = array (
'Foyer' => $foyer,
'Common' => $common,
'North' => $north,
'South' => $south
);

//print contents

//var_dump($offices);
$offices=$_POST['offices'];
 

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 

tekpr00 (IS/IT--Management)
24 Oct 11 19:45
How would you suggest I call the array from the inside a switch statement

Thanks.
Geates (Programmer)
24 Oct 11 20:37
the select tag in the form has the name "office", so

CODE

switch($_POST['office'])

-Geates

"I hope I can chill and see the change - stop the bleed inside and feel again.  Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 

tekpr00 (IS/IT--Management)
24 Oct 11 20:57
I changed it as you suggested. Even with that only common is showing the print out and it is not showing any of the variables in the array.

CODE


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
 <head>
  <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
  
  <title> Employee Office Array </title>
  
 </head>
 <body>

<form action="emp_office_array.php" method="post">

<p>Office:
<select name ="office">
<option value="">Pick One</option>
<option value="foyer">Foyer</option>
<option value="common">Common</option>
<option value="north">North</option>
<option value="south">South</option>
</select></p>

<input type="submit" name="submit"
 value="Query" />

<?php
//Create first array:
$foyer = array(0=> "1. John Smith");

//create second array:
$common = array(0=> "1. Fred Flintstone" , "2. Ann Jones");

//create third array:
$north = array(0=> "1. Pebbles Flintstone", "2. Dino Flintstone");

//create fourth array:
$south = array(0=> "1. Betty Rubble", "2. Barney Rubble", "3. Great Gazoo");

//creat associtive array:
$offices = array (
'Foyer' => $foyer,
'Common' => $common,
'North' => $north,
'South' => $south
);

//print contents

//var_dump($offices);
//$offices_switch=$_POST['offices'];
switch($_POST['office']){
    case 'Foyer':
    print "<p>Employee in Foyer is<i>{$offices['Foyer'][0]}</i>.</p>";
    break;
    case 'common':
    print "<p> Employee in Common are<i>{$offices['Common'][0][1]}</i>.</p>";
    break;
    print "<p> Employee in North are</p>";
    print "<p><i>{$offices['North'][0][1]}</i>.</p>";
    break;
    print "<p> Employee in South are</p>";
    print "<p><i>{$offices['South'][0][1][2]}</i>.</p>";
    break;
}//end of switch

?>
 </form>
</body>
</html>
tekpr00 (IS/IT--Management)
25 Oct 11 0:42
Here is my latest code, please help me.

CODE

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
 <head>
  <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
  
  <title> Employee Office Array </title>
  
 </head>
 <body>

<form action="emp_office_array.php" method="post">

<p>Office:
<select name ="office">
<option value="">Pick One</option>
<option value="foyer">Foyer</option>
<option value="common">Common</option>
<option value="north">North</option>
<option value="south">South</option>
</select></p>

<input type="submit" name="submit"
 value="Query" />

<?php
//Create first array:
$foyer = array(0=> ' John Smith');

//create second array:
$common = array(0=> '1. Fred Flintstone' , '2. Ann Jones');

//create third array:
$north = array(0=> '1. Pebbles Flintstone', '2. Dino Flintstone');

//create fourth array:
$south = array(0=> '1. Betty Rubble', '2. Barney Rubble', '3. Great Gazoo');

//creat associtive array:
$offices = array (
'Foyer' => $foyer,
'Common' => $common,
'North' => $north,
'South' => $south
);

//print contents

//var_dump($offices);
//$offices_switch=$_POST['offices'];
switch($_POST['office']){
    case 'foyer':
    print "<p>Employee in Foyer is<i>{$offices['Foyer'] [0]}</i>.</p>";
    break;
    case 'common':
    print "<p> Employee in Common are<i>{$offices['Common'][0][1]}</i>.</p>";
    break;
    case 'north':
    print "<p> Employee in North are<i>{$offices['North'][0][1]}</i>.</p>";
    break;
    case 'south':
    print "<p> Employee in South are<i>{$offices['South'][0][1][2]}</i>.</p>";
    break;
}//end of switch
?>
 </form>
</body>
</html>
merlinx (Programmer)
7 Mar 12 14:03
you should try it perhaps this way:

$offices = array (
'foyer' = array(0 => ' John Smith'),
'common' = array(0 => '1. Fred Flintstone' , 1 => '2. Ann Jones'),
'north' = array(0=> '1. Pebbles Flintstone', 1 => '2. Dino Flintstone'),
'South' = array(0=> '1. Betty Rubble', 1 => '2. Barney Rubble', 2 => '3. Great Gazoo'));
 

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close