decypher Posted July 22, 2007 Share Posted July 22, 2007 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? Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted July 22, 2007 Share Posted July 22, 2007 You didn't specify a form action. Try: <form action= "basicmultiarray.php" method="post"> The default method is get. Quote Link to comment Share on other sites More sharing options...
decypher Posted July 22, 2007 Author Share Posted July 22, 2007 ahh ok..I'll give it a go Quote Link to comment Share on other sites More sharing options...
decypher Posted July 22, 2007 Author Share Posted July 22, 2007 It didn't work...I've tried it without all the '$cityA = $_POST['cityA'];' or similar coding but i get the same thing... Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted July 22, 2007 Share Posted July 22, 2007 Just spotted it. The keys of the arrays, like varaibles, are case sensitive. Try using: $cityA = $_POST['CityA']; $cityB = $_POST['CityB']; Note the capital C. Quote Link to comment Share on other sites More sharing options...
decypher Posted July 22, 2007 Author Share Posted July 22, 2007 Got it working...Thanks alot everyone *thumbs up* Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.