OK...
Here's what I got...
I have a MySQL DB with a table called 'details' and one called 'apartments'...
The 'apartments' table has the address and such while the 'details' table has the 'Rent' field...
The user searches by using a form that has $min_rent and $max_rent dropdowns as well as a bunch of checkboxes for features the user would like in a place...
Anyways, when they fill out the form it gets sent to the results.php page which has a query that gets all of the listings in the 'details' table that are in the rent range selected. The information is then sent into a loop where I extract the value from the ['AptID'] field of the 'details' table, and place it in a variable ($aptid_1). I have an included file that takes the $aptid_1 and runs it through a mess of stuff to come up with how well the apartment matches the features checked in the form. It results in a variable named $match_percent. I then use the $aptid_1 again to query the 'apartments' table by 'AptID' to get the listing's address information. Now I display the address information, rent, and match % in the table. Since there is always only one row in this query due to the AptID, the loop ends and the first loop continues with the next result from the Rent query...
What I end up with is a table that has all of the information I need.
The problem is that I want to sort it by the Match Percent column...
The solution that I have come up with is this...
Instead of displaying the results right away, I want to load it all, especially the $match_percent, into a new array...
Then I can take this array and display it in the table instead...
This way I can sort my the Match % column...
Unfortunately I have no idea how to create and load up a new array other than querying a MySQL DB...
Is it possible to create an array that is populated as the loop runs...?
I've put the code below for the results.php page...
If you want to see the pages as they are...
www.bnrestaurants.com/test/search/search_form.php
$listing_result = mysql_query("SELECT *
FROM details
Where Rent
BETWEEN $min_rent
AND $max_rent
",$db);
if ($listing_myrow = mysql_fetch_array($listing_result))
{
// Start Table
echo "<B> Apartment List </B><P></P>";
echo "<table border=1>";
echo "<tr>
<td>Address</td>
<td>Apt</td>
<td>City</td>
<td>Available</td>
<td>Match %</td>
</tr>";
do
{
// Set Apt ID
$aptid_1 = $listing_myrow["AptID"];
// Run new query on apartments table using $aptid_1
// Set up query
$apt_result = mysql_query("SELECT *
FROM apartments
Where AptID=$aptid_1
",$db);
if ($apt_myrow = mysql_fetch_array($apt_result))
{
include("match_percent.php");
do
{
printf("
<tr>
<td>
%s
</td>
<td>
%s
</td>
<td>
%s
</td>
<td>
%s
</td>
<td>
<a href=\"show_id.php?id=" .$apt_myrow['AptID'] . "\">$match_percent</a>
</td>
</tr>",
$apt_myrow['AptAddress'],
$apt_myrow['AptApt'],
$apt_myrow['AptCity'],
$apt_myrow['AptAvailable']);
}
while ($apt_myrow = mysql_fetch_array($apt_result));
}
else
{
echo "Sorry, no records were found!";
}
}
while ($listing_myrow = mysql_fetch_array($listing_result));
echo "</table>";
}
else
{
echo "Sorry, no records were found here!";
}
?>
Any help would be greatly appreciated...