Results 1 to 7 of 7

Thread: need help with include

  1. #1
    Join Date
    Apr 2006
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Red face need help with include

    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?

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    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.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Apr 2006
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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?

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    The error is due to all those asterisks.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Apr 2006
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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.

  6. #6
    Join Date
    Apr 2006
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Talking

    whoo! finally got it working! Thanks a lot!

  7. #7
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    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.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •