We help IT Professionals succeed at work.
Get Started

Best Way to to Execute functions and write to a database within a while loop

Ron1959
Ron1959 asked
on
385 Views
Last Modified: 2012-05-12
I want to use the Google Geocode system to look up Lat/Long coordinates on addresses which are in a MySQL database and write them back to the same database.

I am looking for suggestions about the best approach.

The code I'm using to lookup and write back the coordinates is in two php files, one called by the other.  Since they must go to Google's server to do the lookup, there is some delay.

I have tried calling those php files from within the while loop used to step through the database, but it only writes the coordinates to the first record.  Perhaps I need to pause the while loop and make it wait for a return from the Google lookup?

<table>
  <?php do { ?> 
  <tr>
    <?php echo $row_rsContacts_List['First_Name']; ?></td>
    <?php echo $row_rsContacts_List['Last_Name']; ?></td>
    <?php echo $row_rsContacts_List['Address1']; ?></td>
    <?php echo $row_rsContacts_List['Address2']; ?></td>
    <?php echo $row_rsContacts_List['City']; ?></td>
    <?php echo $row_rsContacts_List['State']; ?></td>
    <?php echo $row_rsContacts_List['Zip']; ?></td>

    <?php  // Set address values to session variables to be used by the 
		   // files that cdo the Google Geocode lookup
				$_SESSION['MAP_Geocode'] = "Y";
				$_SESSION['MAP_Street'] = $row_rsContacts_List['Address1'];
				$_SESSION['MAP_City'] = $row_rsContacts_List['City'];
				$_SESSION['MAP_State'] = $row_rsContacts_List['State'];
				$_SESSION['MAP_Zip'] = $row_rsContacts_List['Zip'];
		// Open self-closing popup window load the files that do the Google Geocode lookup
		echo "<script type='text/javascript'>
			WindowName = window.open('../mapping/geocode.php', 'Geocode', 'width=400,height=200,scrollbars=yes');
			WindowName.moveTo(400,200);
			WindowName.focus();
			</script>";				
	?>
    <?php $rownum ++; ?>
  </tr>
  <?php } while ($row_rsContacts_List = mysql_fetch_assoc($rsContacts_List)); ?>
</table>  

Open in new window


Solutions would be appreciated!


Comment
Watch Question
Billing Engineer
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2009
Commented:
This problem has been solved!
Unlock 3 Answers and 8 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE