I have a query, which roughly works like....
Search1. uses the users postcode/zipcode and finds the coords for it from table1.
Search2. Then searchs for any postcodes within +/- 10 degrees of those coords from table1.
//this lets me know all the postcodes nearby to the one the user inputted.
Search3. Then search table 2 for anyone with any of those postcodes which also matches another criteria (that is dates they are free)
It's set up in a while loop to process things, however this returns everything in order of Search 2 whereas i'd like to order things by a value in Search3. I did try swapping those 2 searchs around, but got into a bit of a mess. Ok, ok a big mess.
Can anyone help me get things so they can be returned according to an order from 'search3'.
Current code - abridged.
//search1
$result = mysql_query("SELECT postcode1, lon, latt FROM postcode WHERE postcode1='$postcode1'")
//search2
$result2 = mysql_query("SELECT * FROM postcode WHERE lon BETWEEN {$lonMIN} AND {$lonMAX} AND latt BETWEEN {$latMIN} AND {$latMAX}") or die(mysql_error());
// see if any rows were returned
if (mysql_num_rows($result2) > 0) {
//Start a while loop for any results in database with postcode between those from search2
while($row2 = mysql_fetch_row($result2)) {
//For each of the postcodes returned from proximity search, check to see if date matches
//row2[0]= postcode from search
$result3 = mysql_query("SELECT * FROM co_details WHERE postcode1 = '$row2[0]' AND (date0 = '$sqldate' OR date1 = '$sqldate' OR date2='$sqldate')") or die(mysql_error());
while($row3 = mysql_fetch_array($result3))
{
//Print basic details for companies which match the area specified and the date required.
echo ucwords($row3['coname']);
}
//end while
}
//end 'no results' if.
}
Thank-you