Log in

View Full Version : need help with include



cow_manuver
06-02-2006, 05:10 PM
I have this script I got from:
http://www.falconsolution.com/distance-calculator/

what I have is the "sample.php", and the "DrivingDistanceCalcFunctions.php" which is encrypted. The source for "sample.php" can be viewed here: http://www.flybydesign.net/PHP/sample.txt

I am learning PHP as I go, so I'm just looking to be pointed in the right direction. I need to add an extra stop into this sample. Here is the code I've been trying to use, but I get an error,

<?
do {
$fromZipCode = $fromZipCodeNew;
$fromZipCode2 = $fromZipCode;
$fromZipCode2 = 0;

// Code below, is what I'm told to add on their webpage
// I'm trying to run DrivingDistanceCalcFunctions.php again after I have
// changed the variables and saved them to other variables

**include( "DrivingDistanceCalcFunctions.php" );
**getDistance( $fromZipCode, $toZipCode );
**echo "Distance between ".$FromCity."(".$FromState.") and
**********".$ToCity."(".$ToState.") is <b>".$DrivingDistance."</b> miles";

} while($fromZipCode2 > 0);
?>


I'm not sure if a do/while is the best way to do this, but I also tried an if/else that gives a different error, but the problem is, the line it tells me the error is on, is not the same line that the actual code it refers to is on, so thats probably what is throwing me off the most...

Can someone please help me?

djr33
06-02-2006, 09:28 PM
random note... the .phps extension will color code the source... a bit nicer on the eyes than .txt. no big deal, though.


from what I can tell... it would REALLY help to see the source of the other function.

however... if you just want to do three places, ALL you need to do is this:
1. Make a page or function that calculates between two pages.
2. include that page, or call that function TWICE, once from A-B, and another from B-C. Then ADD those two, and you've got the distance from A-C. Display that.

The point is... don't try to change anything... just run it twice as is, and add those results.

cow_manuver
06-03-2006, 06:10 PM
Hey thanks for replying djr33. That .phps thing is definitely going to be useful. Currently I don't think my server is configured properly for it, but I'll ask them whats up with that.

I'm a little confused

In step 1. when you say to make a function that calculates between 2 pages, what do you mean?

In step 2. Do you mean that I should put the include into the function definition? Then I just call the function twice?

Twey
06-03-2006, 06:52 PM
The error is due to all those asterisks.

cow_manuver
06-03-2006, 06:59 PM
hrm, the astericks aren't in the code, when i copied it here, they appeared for some reason.


But I'm currently trying what djr33 suggested. Encasing the code in a function and calling that function twice.

I just need to figure out the best way of running it once, and saving that to a variable, then copying the value of "fromZipCode2" to "fromZipCode" (which is the variable accepted by the include("DrivingDistanceCalcFunctions.php")) and running it the 2nd time to save that to another variable so I can add them.

cow_manuver
06-03-2006, 10:00 PM
whoo! finally got it working! Thanks a lot!

djr33
06-03-2006, 11:13 PM
The point is... don't try to change anything... just run it twice as is, and add those results.

That's the point of my above post. The other stuff might not be the best or easiest suggestions.

Just, yeah, find some way to do it twice and add.... that's it.

A function would be best if you can make it fit into it and work well.

If not, you could try the inlude thing... I just meant that you could use EITHER an include or function, using one or the other twice, to get the two different distances.

I didn't mean to mix a function in an include, sorry 'bout that phrasing.