Jump to content

[SOLVED] Multi-Dimensional Array


decypher

Recommended Posts

Html:

<html>
<head>
<title>Basic multi-dimensional array</title>
</head>
<body>

<h1> Basic 2D Array</h1>

<form action= basicmultiarray.php>
<table border = 1>
<tr>
  <th>First City</th>
  <th>Second City</th>
<tr>

<!-- note each option value is numeric -->

<tr>
  <tD>
  <select name = "CityA">
   <option value = 0>Indianapolis</option>
   <option value = 1>New York</option>
   <option value = 2>Tokyo</option>
   <option value = 3>London</option>
</seltect>
</td>

<td>
<select name = "CityB">
   <option value = 0>Indianapolis</option>
   <option value = 1>New York</option>
   <option value = 2>Tokyo</option>
   <option value = 3>London</option>
</seltect>
</td>
</tr>

<tr>
  <td colspan = 2>   
    <Input type = "submit"
           Value= "calculate distance">
  </td>
</tr>
</table>
</body>
</html>

 

PHP:

<html>
<head>
<title> distance Calculator</title>
</head>
<body>
<method = "POST">
<?php

$city = $_POST['array'];
$cityA = $_POST['cityA'];
$cityB = $_POST['cityB'];

$city = array("Indianapolis","New York","Tokyo","London");

$distance = array(
array (0, 648, 6476, 4000),
array (648, 0, 6760, 3470),
array (6476, 6760, 0, 5956),
array (4999, 3470, 5956, 0)
);

$result =$distance[$cityA][$cityB];
print "<h3>The distance between ";
print "$city[$cityA] and $city[$cityB]";
print " is $result miles.</3>";

?>

</body>
</html>

 

Problem is that when i do the query as such all I get is...'The distance between and is miles.' not gettin the city names or miles...any suggestions?

 

Many thanks in advanced

 

P.S This problem does keep re-occuring when all coding is right...Any reasons why the data doesn't show when I sumbit the button?

Link to comment
Share on other sites

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.