Distance between cities

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jetlife76
Forum Newbie
Posts: 24
Joined: Tue Oct 18, 2011 1:21 pm

Distance between cities

Post 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.";}}
 
?>
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Distance between cities

Post 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.
Wendi
Forum Newbie
Posts: 1
Joined: Thu Mar 29, 2012 2:50 pm

Re: Distance between cities

Post 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.
Post Reply