Page 1 of 1

Distance between cities

Posted: Sun Nov 13, 2011 6:46 pm
by jetlife76
Having trouble with a distance program i am working on. The user has two choices(radio buttons) dallas or chicago. They tthen choose a destination from a selection list. Output should be the distance, time it takes to drive and walk those distances. My output page is only displaying the heaings and titles. Can someone please tell me what i am doing wrong..

here's what i have:

Code: Select all

<?php
$cities =array ('Dallas' => 803, 'Toronto' => 435, 'Boston' => 848, 'Nashville' => 406, 'Las Vegas' => 1526, 'San Francisco' => 1835, 
				'Washington, DC' => 595, 'Miami' => 1189, 'Pittsburgh' => 409);
$cities2 = array ('Chicago' => 803, 'Toronto' => 1202, 'Boston' => 1548, 'Nashville' => 615, 'Las Vegas' => 1073, 'San Francisco' => 1483, 
				'Washington, DC' => 1181, 'Miami' => 1107, 'Pittsburgh' => 1068);
				
	if (isset($_POST['dal'])  && isset($cities['destination'])) {
		$distance = $cities['destination'];
	if (isset($_POST['chi']) && isset($cities['destination'])){
		$distance = $cities2['destination'];
		
		$time = round(($distance / 60), 2);
		$walktime = round(($distance / 5), 2);
		print "The distance between Chicago and <i>['destination']</i> is $distance miles.";
		print "<br> Driving at 60 Miles per hr. it would take $time hrs.";
		print "<br> Walking at 5 Miles per hr. it would take $walktime hrs.";}
	else {
		print "Please select a Starting city and a Destination.";}}
 
?>

Re: Distance between cities

Posted: Sun Nov 13, 2011 9:04 pm
by Celauran

Code: Select all

if (isset($_POST['dal'])  && isset($cities['destination'])) {
There is no 'destination' key in your cities array, so this will always evaluate to FALSE.

Re: Distance between cities

Posted: Thu Mar 29, 2012 2:58 pm
by Wendi
You can take help from an expert to remove the fault of your program and make it perfect so that you can calculate distance between cities and other distances among various places. I am telling this because it seems that, your program has some faults.