Hi, I'm still learning php & i need a little help..
I am trying to sort the variable $price from highest to lowest - ie. i need to sort the data in the price column so i can display it in html highest price first..
This is for a realty website - and i'm trying to display the registered users (realtor)
listings, highest price first -
Please forgive me if my code is ugly - i'm a newbie...
First i use this query to pull the user's listings:
$sql = "SELECT listingsdb_id, listingsdb_title FROM " . $config['table_prefix'] . "listingsdb WHERE userdb_id = $user";
This returns a group of listings for a specified user - in the order they appear in the database in the column --> listingsdb_id
Then i am pulling the price for a specific listing from the database with the following query:
$sql="SELECT listingsdbelements_field_value FROM ".$config['lang_table_prefix']."listingsdbelements WHERE listingsdb_id=$ID AND listingsdbelements_field_name='price'";
Here's the code sequence i'm working with:
$sql = "SELECT listingsdb_id, listingsdb_title FROM " . $config['table_prefix'] . "listingsdb WHERE userdb_id = $user";
$recordSet = $conn->SelectLimit($sql, 50, 0);
if ($recordSet === false) {
$misc->log_error($sql);
}
if ($recordSet->RecordCount() > 0) {
$display .= '';
while (!$recordSet->EOF) {
$ID = $misc->make_db_unsafe ($recordSet->fields['listingsdb_id']);
$Title = $misc->make_db_unsafe ($recordSet->fields['listingsdb_title']);
// start insert Pull price from database
$sql="SELECT listingsdbelements_field_value FROM ".$config['lang_table_prefix']."listingsdbelements WHERE listingsdb_id=$ID AND listingsdbelements_field_name='price'";
$recordset=$conn->Execute($sql);
$price=$recordset->fields['listingsdbelements_field_value'];
I think somewhere i need to use the following statement in my sql call:
ORDER BY listingsdbelements_field_name='price' DESC
But it isn't working for me :o(
any guidance is greatly appreciated ...