I've been working with a script that allows users to look up other users in their area based on their zip code. I attempted the script myself but the whole lat/long thing was a bit much for me to understand, so I settled for one that I found on the net. The problem that I'm having is that the query results are loaded into an array such as $zips = $z->get_zips_in_range("".$my_zip."", "".$distance."", _ZIPS_SORT_BY_DISTANCE_ASC, true);
and use a foreach loop to iterate through the resutls, ex. foreach ($zips as $key => $value) {}
with $key being the zip code and $value being the distance. This works just fine and displays the expected results when echoed, but the problem is that I need to use a while loop to run through the result set and can't figure out how to alter the code to get what I want.
I would like to take the resulting zip codes ($key) in this case and run it through another query. I'm fully aware that this won't work (as expected) but just to give you an idea of what I'd like to do, here is an example:
$zips = $z->get_zips_in_range("".$my_zip."", "".$distance."", _ZIPS_SORT_BY_DISTANCE_ASC, true);
foreach ($zips as $key => $value) {}
$sql="SELECT * FROM users WHERE zip='$key'"; //<-- Just an example
$res=mysql_query($sql)or die(mysql_error());
$i = 0;
$num_of_cols = 5;
echo "<table cellspacing=\"10\" cellpadding=\"10\"><tr>";
while($row = mysql_fetch_array($res)) {
$fname=$row['first_name'];
$age=$row['age'];
$id=$row['id'];
$sql1="SELECT prof_pic FROM user_profile WHERE user_id='$id'";
$res1=mysql_query($sql1);
$numr=mysql_num_rows($res1);
while($r1=mysql_fetch_array($res1)){
$pic=$r1['prof_pic']; } etc.
Any ideas how I can do this ? I can provide code from the .class that defines the function 'get_zips_in_range' if needed.