Jump to content

Price descending order problem


dave_cdv

Recommended Posts

I'm hoping someone can help me with this as I'm fairly new to MySQL.

 

I have a holiday rental peoperty website and at the moment all the properties are listed in search results are ordered by the home_no (a unique auto generated number) this gives the first properties that sign up an advantage as they are always at the top of the search results.

 

Therefore I want to give an option to sort by lowest price.

 

The problem is that the rates are stored in a seperate table to the value that is searched (city).

 

Therefore I want to select home_no from the one table, and sort by the value of the lowest price field in another table.

 

Does that make sense? Any ideas on how I should do this?

Link to comment
Share on other sites

im sorry im getting back to this stuff after a long break so my refrences are messed around.

 

I have 2 tables Table 1 stores book info

 

Table 2 stores ranks of the books in your case price.

 

So this is what i did to display my data based on ranks

 

 

$sql2 = 'SELECT * FROM `rank` ORDER BY `RankUK` ASC LIMIT 0, 100 ';
$results2= mysql_query($sql2) or die(mysql_error());
$count2 =0;

while($row2 =mysql_fetch_array($results2)){
$count2 = $count2+1;




$model =$row2['book_ISBN'];
$RankUK=$row2['RankUK'];
$RankUS=$row2['RankUS'];
$RankCAN=$row2['RankCAN'];



$sql = 'SELECT * FROM `products` WHERE `book_ISBN` = "'.$model.'"';

$result = mysql_query($sql);
if (!$result) {
    echo 'Could not run query: ' . mysql_error();
    exit;
}
$row = mysql_fetch_row($result);
$title =$row[1];
$Author=$row[2];
$model=$row[3];

echo "<tr><td>$count2</td><td>$title </td><td>$Author</td><td>$model</td><td>$RankUK</td><td>$RankUS</td><td>$RankCAN</td></tr>";




}// edn while loop


 

In my case my secondary field is the  book_ISBN  you have to do something similar treat the price table like my rank table and then run the query for your product data inside the while loop

 

i hope this helps

 

 

 

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.