harkly Posted July 2, 2010 Share Posted July 2, 2010 I have a code that does a search on zip codes and returns ones that are in a specified range. This is done in an array. I am very very new to arrays, with this being my real first one! What I need to do is take all the zip codes that it returns, use them to find & pull info from other tables and echo it out. Can someone point me in the right direction of how to do this? So it will go something like this:: from table user find all zips from within a 10 miles radius of 90210 select the userID then select all info from table background Link to comment https://forums.phpfreaks.com/topic/206530-foreach/ Share on other sites More sharing options...
harkly Posted July 2, 2010 Author Share Posted July 2, 2010 my code I have $result = mysql_query("SELECT userID FROM user WHERE zip IN (". $zips_in_range .")"); while ($row = mysql_fetch_assoc($result) ) { foreach ($row as $userID) { extract($row, EXTR_PREFIX_SAME, "userID"); echo "This is the userID - $userID <br>"; echo "Select * FROM photos WHERE userID = $userID <BR>"; $query = ("Select * FROM photos WHERE userID = $userID "); while ($r=mysql_fetch_array($query)) { $userID=$r["userID"]; $photo_1=$r["photo_1"]; echo " $userID & $photo_1"; } } } my results This is the userID - kelly Select * FROM photos WHERE userID = kelly Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/content/i/d/2/id2294/html/singles/results.php on line 32 This is the userID - adfggg Select * FROM photos WHERE userID = adfggg Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/content/i/d/2/id2294/html/singles/results.php on line 32 This is the userID - neer Select * FROM photos WHERE userID = neer Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/content/i/d/2/id2294/html/singles/results.php on line 32 Link to comment https://forums.phpfreaks.com/topic/206530-foreach/#findComment-1080442 Share on other sites More sharing options...
vmicchia Posted July 2, 2010 Share Posted July 2, 2010 $query = ("Select * FROM photos WHERE userID = $userID "); $result = mysql_query($query); while ($r=mysql_fetch_array($result)) { $userID=$r["userID"]; $photo_1=$r["photo_1"]; echo " $userID & $photo_1"; } I think that change should take care of it. Link to comment https://forums.phpfreaks.com/topic/206530-foreach/#findComment-1080444 Share on other sites More sharing options...
harkly Posted July 3, 2010 Author Share Posted July 3, 2010 Thanks this worked great! I just had to add '' to the $userID in this line $query = ("Select * FROM photos WHERE userID = $userID "); Link to comment https://forums.phpfreaks.com/topic/206530-foreach/#findComment-1080851 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.