nc_brox Posted August 7, 2007 Share Posted August 7, 2007 Hi guys, I've had a look through the exisiting posts but can't find anything that points me in the right direction for this - I hope someone can help! Basically I have 2 tables, one called register which holds the users details and one called postcodes that holds a general list of postcodes and locations. I have a form where the user can select how far they are prepared to travel (at this point the user is already registered so their details are in the register table). So what I need to do, is find the users postcode in the register table (I am using sessions which stores the members ID), for which I have the following code (which works): //find users postcode from register table $query = mysql_query("SELECT Postcode FROM register WHERE ID = ". $_SESSION['member_ID'] .";"); $getpc = mysql_fetch_array($query); $postcode = $getpc['Postcode']; I then need to find all the postcodes from the postcode table which are within a certain distance of the members postcode (this code works aswell): $max_gridn = $gridn + $distance //I have already defined $gridn and $distance earlier in the code $query3 = mysql_query("SELECT Pcode FROM postcodes WHERE Grid_N <='$max_gridn'"); while($assoc = mysql_fetch_assoc($query3)){ echo '<br />'.$assoc['Pcode']; } I don't really need to display these results as I have above, I've just done that so I can see that it works. Now for the bit that I'm stuck on. I need to take each Pcode that is returned in query3 and see if there are any records in the 'register' table which match that Pcode..... I think I need to do something with arrays and possibly loops but I am completely stumped with this, any help would be much appreciated!! Quote Link to comment Share on other sites More sharing options...
fenway Posted August 10, 2007 Share Posted August 10, 2007 Well, you can skip the whole array business, and issue a simple join to compare the user's postal to all postals... as for the distances, well, that depends how you've stored it, e.g. long/lat, etc., mysql has functions for this. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.