Page 1 of 1

PHP/Javascript Question

Posted: Wed Jul 16, 2008 11:43 am
by tpra21
I am using a Google Maps API to calculate the distance between two addresses. Unfortunately, I need to do this in a loop for several thousand to/from address combinations and then store the distance (miles between two addresses) into a variable and then a database. My issue is getting the Javascript variable into the PHP variable over and over without refreshing the page (passing it through a form or URL).

Hopefully I am explaining my issue clearly. Below is the basic idea.

Code: Select all

read through DB get from address
     read through and process all to addresses with from address
          javascript distance var = google API result (this line is echoed/embedded javascript in PHP)
          place javascript distance var into PHP distance var for later iserting into DB
     end read
end read
I have looked all over th einternet. Any help or ideas would be awesome.

Thanks,

Adam

Re: PHP/Javascript Question

Posted: Wed Jul 16, 2008 12:58 pm
by alex.barylski
Use AJAX to send the value to a PHP script on each iteration

OR

Cache the results in a JavaScript array and when finished submit the whole enchilada

Re: PHP/Javascript Question

Posted: Thu Jul 17, 2008 6:54 pm
by tpra21
Thanks for the reply. Although new to Ajax, I think I will do some reading and give that approach a shot. It sounds like an awesome technology. I know I am using some Shadowbox software on my site now, and it is very impressive.