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? Link to comment https://forums.phpfreaks.com/topic/61289-solved-multi-dimensional-array/ 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. Link to comment https://forums.phpfreaks.com/topic/61289-solved-multi-dimensional-array/#findComment-304965 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 Link to comment https://forums.phpfreaks.com/topic/61289-solved-multi-dimensional-array/#findComment-304967 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... Link to comment https://forums.phpfreaks.com/topic/61289-solved-multi-dimensional-array/#findComment-304971 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. Link to comment https://forums.phpfreaks.com/topic/61289-solved-multi-dimensional-array/#findComment-304976 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* Link to comment https://forums.phpfreaks.com/topic/61289-solved-multi-dimensional-array/#findComment-304983 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.