Jump to content

Multi Diminutional Array Help


Go to solution Solved by webdevdea,

Recommended Posts

I am supposed to have an array so that when you choose a customer and one of the information items, its displays, well its almost there 

here is my php and html,

when you run it it hast cust_num or cust_city or cust_state instead of the data itself 

so help please

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="EN" dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Didja Know?r</title>
</head>
<body>
<h1>Didja Know?</h1>

<?php 
//create arrays
$cust_num = array (
  "DeAnna" => 069,
  "Joshua" => 088,
  "Eden" => 087,
  "Aubrey" => 2009
  );
$cust_addr = array (
  "DeAnna" => 102,
  "Joshua" => 113,
  "Eden" => 104,
  "Aubrey" => 420
  );
$cust_city = array (
  "DeAnna" => "Atlanta",
  "Joshua" => "Columbus",
  "Eden" => "Smyrna",
  "Aubrey" => "Vinnings"
  );
$cust_email = array (
  "DeAnna" => "deanna@gmail.com",
  "Joshua" => "josh@gmail.com",
  "Eden" => "eden@gmail.com",
  "Aubrey" => "Aubrey@gmail.com"
  );

//set up master array
$distance = array (
  "DeAnna" => $cust_num,
  "Joshua" => $cust_addr,
  "Eden" => $cust_city,
  "Aubrey" => $cust_email
  );

$cust_name = filter_input(INPUT_POST, "cust_name");
$cust_info = filter_input(INPUT_POST, "cust_info");

$result = $distance[$cust_name][$cust_info];
print "<h3>$cust_name and $cust_info is $result .</h3>";

?>

</body>
</html>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="EN" dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>DIDJA KNOW</title>
</head>
<body>
<h1>DIDJA KNOW</h1>

<form action = "http://localhost/Assignments php class/assign7.php"
      method = "post">
<table border = "1">

<tr>
  <th>Customer Name</th>
  <th>Customer Info</th>
</tr>

<!-- note each option value is a string -->

<tr>
  <td>
    <select name = "cust_name">
      <option value = "DeAnna">DeAnna</option>
      <option value = "Joshua">Joshua</option>
      <option value = "Eden">Eden</option>
      <option value = "Aubrey">Aubrey</option>
     </select>
   </td>

  <td>
    <select name = "cust_info">
      <option value = "cust_num">Customer Number</option>
      <option value = "cust_addr">Address</option>
      <option value = "cust_city">City</option>
      <option value = "cust_email">email</option>
     </select>
  </td>
</tr>

<tr>
  <td colspan = "2">
    <input type = "submit"
           value = "Didja Know This?" />
  </td>
</tr>
</table>
</form>

</body>
</html>
Link to comment
https://forums.phpfreaks.com/topic/279813-multi-diminutional-array-help/
Share on other sites

Ok a dropdown comes up and you choose a person's name, then in another drop down you choose customer number,address,city,email and it is supposed to come up with the name, the data name and the data it comes up with the name and the variable name of the data but that's it.. does that help you ? 

 you can go to this link and see what is happening, its a link from an old course I took but I can still up load files and play with them 

http://www.ctcsports.org/upload/Fall2012/CIST1520/900104329/Assignment13/Assignment7.html

Oh ok, lol let me check it out and see, 

Ok so I have changed my php could you see if its anything close to right lol 


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
<html lang="EN" dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Didja Know?r</title>
</head>
<body>
<h1>Didja Know?</h1>
 
<?php 
//create arrays
$cust069 = array (
  "cust_name" => "DeAnna",
  "cust_addr" => 103,
  "cust_city" => "Atlanta",
  "cust_email" => "d@d.com"
  );
$cust088 = array (
   "cust_name" => "Josh",
  "cust_addr" => 104,
  "cust_city" => "Columbus",
  "cust_email" => "J@J.com"
  );
$cust087= array (
   "cust_name" => "Eden",
  "cust_addr" => 107,
  "cust_city" => "Smyrna",
  "cust_email" => "E@E.com"
  );
$cust2009 = array (
   "cust_name" => "Aubrey",
  "cust_addr" => 103,
  "cust_city" => "Atlanta",
  "cust_email" => "A@A.com"
  );
//set up master array
$customers = array (
  "069" => $cust069,
  "cust088" => $cust088,
  "cust087" => $cust087,
  "cust2009" => $cust2009
  );
 
$cust_name = filter_input(INPUT_POST, "cust_name");
$cust_info = filter_input(INPUT_POST, "cust_info");
 
$customers = $customers[$cust_name][$cust_info];
print "<h3>$cust_name and $cust_info is $customers .</h3>";
 
?>
 
</body>
</html>
 

I know I have something worded wrong, one of my variables maybe in the wrong place????

Edited by webdevdea

I changed the html some 

  <td>
    <select name = "cust_name">
      <option value = "DeAnna">069</option>
      <option value = "Joshua">088</option>
      <option value = "Eden">087</option>
      <option value = "Aubrey">2009</option>
     </select>
   </td>

  <td>
    <select name = "cust_info">
      <option value = "cust_name">Customer Name</option>
      <option value = "cust_addr">Address</option>
      <option value = "cust_city">City</option>
      <option value = "cust_email">email</option>
     </select>
  </td>
</tr>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="EN" dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Didja Know?r</title>
</head>
<body>
<h1>Didja Know?</h1>

<?php 
//create arrays
$cust069 = array (
  "cust_name" => "DeAnna",
  "cust_addr" => 103,
  "cust_city" => "Atlanta",
  "cust_email" => "d@d.com"
  );
$cust088 = array (
   "cust_name" => "Josh",
  "cust_addr" => 104,
  "cust_city" => "Columbus",
  "cust_email" => "J@J.com"
  );
$cust087= array (
   "cust_name" => "Eden",
  "cust_addr" => 107,
  "cust_city" => "Smyrna",
  "cust_email" => "E@E.com"
  );
$cust2009 = array (
   "cust_name" => "Aubrey",
  "cust_addr" => 103,
  "cust_city" => "Atlanta",
  "cust_email" => "A@A.com"
  );
//set up master array
$customers = array (
  "069" => $cust069,
  "cust088" => $cust088,
  "cust087" => $cust087,
  "cust2009" => $cust2009
  );

$cust_name = filter_input(INPUT_POST, "cust_name");
$cust_info = filter_input(INPUT_POST, "cust_info");

$customers = $customers[$cust_name][$cust_info];
print "<h3>$cust_name and $cust_info is $customers .</h3>";

?>

</body>
</html>

so I have something confused when calling out the $cust_info variable

I worked on the Php file a little more, maybe closer? 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="EN" dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Didja Know?</title>
</head>
<body>
<h1>Didja Know?</h1>

<?php 
//create arrays
$cust069 = array (
  "cust_name" => "DeAnna",
  "cust_addr" => 103,
  "cust_city" => "Atlanta",
  "cust_email" => "d@d.com"
  );
$cust088 = array (
   "cust_name" => "Josh",
  "cust_addr" => 104,
  "cust_city" => "Columbus",
  "cust_email" => "J@J.com"
  );
$cust087= array (
   "cust_name" => "Eden",
  "cust_addr" => 107,
  "cust_city" => "Smyrna",
  "cust_email" => "E@E.com"
  );
$cust2009 = array (
   "cust_name" => "Aubrey",
  "cust_addr" => 103,
  "cust_city" => "Atlanta",
  "cust_email" => "A@A.com"
  );
//set up master array
$customers = array (
  "cust069" => $cust069,
  "cust088" => $cust088,
  "cust087" => $cust087,
  "cust2009" => $cust2009
  );

$cust_name = filter_input(INPUT_POST, "cust_name");
$cust_info = filter_input(INPUT_POST, "cust_info");

$did_ja_know = $customers[$cust_name][$cust_info];
print "<h3>$cust_name and $cust_info is $did_ja_know.</h3>";

?>

</body>
</html>

Ok here is what I am working with right now, I still am really confused as to how I am messing up.. Help please and thank you ..  

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="EN" dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Didja Know?</title>
</head>
<body>
<h1>Didja Know?</h1>

<?php 
//create arrays
$cust1 = array (
"CustName" => "Fred",
"CustAddress" => "123",
"CustCity" => "Atlanta",
"CustState" => "GA"
);
$cust = array (
"CustName" => "dred",
"CustAddress" => 1293,
"CustCity" => "Atlanhta",
"CustState" => "GA"
);
$cust3 = array (
"CustName" => "Frsded",
"CustAddress" => "132423",
"CustCity" => "Atlan2343ta",
"CustState" => "G23A"
);
$cust4 = array (
"CustName" => "Fre34d",
"CustAddress" => "114323",
"CustCity" => "Atlafdasfnta",
"CustState" => "GafdasA"
);
//set up master array
$customers = array (
"001" => $cust1,
"002" => $cust2,
"003" => $cust3,
"004" => $cust4
);

$CustName = filter_input(INPUT_POST, "CustName");
$cust_info = filter_input(INPUT_POST, "cust_info");

$did_ja = $customers[$CustName][$cust_info];
print "<h3>$CustName and $cust_info is $did_ja. </h3>";

?>

</body>
</html>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="EN" dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>DIDJA KNOW</title>
</head>
<body>
<h1>DIDJA KNOW</h1>

<form action = "http://localhost/Assignments php class/assign7.php"
      method = "post">
<table border = "1">

<tr>
  <th>Customer Number</th>
  <th>Customer Info</th>
</tr>

<!-- note each option value is a string -->

<tr>
  <td>
    <select name = "CustName">
      <option value = "DeAnna">069</option>
      <option value = "Josh">088</option>
      <option value = "Eden">087</option>
      <option value = "Aubs">2009</option>
     </select>
   </td>

  <td>
    <select name = "cust_info">
      <option value = "CustName">Customer Name</option>
      <option value = "CustAddress">Address</option>
      <option value = "CustCity">City</option>
      <option value = "CustState">state</option>

     </select>
  </td>
</tr>

<tr>
  <td colspan = "2">
    <input type = "submit"
           value = "Didja Know This?" />
  </td>
</tr>
</table>
</form>

</body>
</html>

Can you explain to me exactly how you expect your arrays to work as they are currently? This will help you think your problem through. As it stands, your arrays make little sense.

Still having trouble getting my array's to associate, could someone give me a hint as to where I am going wrong? 

 

Can you explain to me exactly how you expect your arrays to work as they are currently? This will help you think your problem through. As it stands, your arrays make little sense.

v

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.