Well I have one select atatement where this array is built up in the correct order, but now I need to get other data from the database according to which id's have been chosen in this array.
The code below still brings them up in no order, but echo's the order they should be in by distance and id before the actual results appear.
Here's my full code so you can understand my needs, thanks a bunch!
$sorter = "SELECT * FROM directory WHERE authorised = 'Y' ";
$sorterResults = mysql_query($sorter);
while ($sorterRow = mysql_fetch_array ($sorterResults)){
$sortpostcode = $sorterRow["postcode"];
$sortid = $sorterRow["id"];
$sortsubscription = $sorterRow["subscription"];
$sortauth = $sorterRow["authorised"];
$sortco = $sorterRow["company"];
$checksortpost = substr("$sortpostcode",0,4);
$distancetocleanersort = calc_postcode_seperation("$dir1","$checksortpost");
$sortarray[$sortid]=$distancetocleanersort;
}
asort($sortarray);
foreach ($sortarray as $key => $val) {
echo "$val = $key<br>";}
//////////////////////////////////////////////////////////////TODAY
//Show results for users that have been authorised by administrator and their clean types have been checked by the user
$directory = "SELECT * FROM directory WHERE authorised = 'Y'";
$directoryResults = mysql_query($directory);
$count_result = mysql_num_rows($directoryResults);
while ($directoryRow = mysql_fetch_array ($directoryResults)){
$id = $directoryRow["id"];
$company = $directoryRow["company"];
$website = $directoryRow["website"];
$details = $directoryRow["details"];
$addressline = $directoryRow["address"];
$postcode = $directoryRow["postcode"];
$number = $directoryRow["number"];
$email = $directoryRow["email"];
$image = $directoryRow["image"];
$clean1_id = $directoryRow["clean1_id"];
$clean2_id = $directoryRow["clean2_id"];
$clean3_id = $directoryRow["clean3_id"];
$clean4_id = $directoryRow["clean4_id"];
$clean5_id = $directoryRow["clean5_id"];
$clean6_id = $directoryRow["clean6_id"];
$subscription = $directoryRow["subscription"];
$authorised = $directoryRow["authorised"];
$checkpost = substr("$postcode",0,4);
IF (strlen($postcode)=='6'){
$checkpost=substr("$postcode",0,3); }
$number1= substr("$number",-4);
$distancetocleaner = calc_postcode_seperation("$dir1","$checkpost");
IF ($website==''){
$company=$company;}
ELSE $company="<a target='_blank' href='http://$website'>$company</a>";
echo"<form method = 'POST' action='compare.php'>";
//Show all details if customer has paid account and is within distance specified by search
IF ($subscription=='PAID' AND $distancetocleaner<$dist AND $authorised =='Y'){
echo"
<center>
<table bgcolor='#ffffcc' width='50%' border ='1' bordercolor='navy'>
<tr>
<td>$company</td><th valign='center' rowspan='5' width='90'><center><img width='90' src='upload/$image'></center></th>
</tr>
<tr>
<td>$addressline, <a href='http://www.multimap.com/map/browse.cgi?pc=$postcode' target='_blank'>$postcode</a></td>
</tr>
<tr>
<td>$number</td>
</tr>
<tr>
<td><a href='mailto:$email?subject=I found you on Cleaners Directory'>$email</a></td>
</tr>
<tr><td>
This cleaner is $distancetocleaner miles from you!
</td></tr>
<tr><td>
Compare:
<input type='checkbox' name='compare[]' value='$id'/>
</td><td>
<a href='fulldetails.php?id=$id'>More Details</a></td></tr>
</table></center><p>";
$count++;
}
//Only show some details for users that have free account
ELSEIF ($subscription == 'FREE' AND $distancetocleaner<$dist AND $authorised =='Y'){
echo"
<center>
<table bgcolor='#ffffcc' width='50%' border ='1' bordercolor='navy'>
<tr>
<td>$company</td>
</tr>
<tr>
<td>$addressline, $postcode</td>
</tr>
<tr>
<td>$number</td>
</tr>
<tr><td>This cleaner is $distancetocleaner miles from you!
</td>
</tr>
<tr><td>
Compare:
<input type='checkbox' name='compare[]' value='$id'/>
</td></tr>
</table></center><p>
</font><p>
";
$count1++;
}}}
I've tried running the foreach around the final select statement and ending the brackets right at the end of the code, problem is the paid accounts appear more than once in the results
I have put the foreach statement around the whole of my next select statement but I'm getting repeated data where the subscription is PAID for my first IF.
foreach ($sortarray as $key => $val) {
}