Jump to content

Help needed diplaying arrays with 2 select queries


nc_brox

Recommended Posts

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!!    ;D

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.