Skip to main content
Inspiring
June 12, 2008
Question

Price not decending or ascending properly

  • June 12, 2008
  • 3 replies
  • 224 views
I am trying to process information and want to order it by price. I have a form to choose to show the price ascending or decending.

I'm getting values like this:
£79,950.00
£52,500.00
£164,950.00
£14,500.00

The prices are stored in my database like this: 52500.00

My SQL statement is:

$query_results = "SELECT *
FROM property
WHERE B_R = 'BUY'
AND Accepted = 'Yes'
AND (City = '$_REQUEST
quote:

' Or Postcode = '%$_REQUEST
quote:

' Or Area = '$_REQUEST
quote:

')
AND NoBeds $NoBeds
AND Cost BETWEEN $_REQUEST[minPrice] AND $_REQUEST[maxPrice]
ORDER BY Cost $_REQUEST[sort]";
I tried ORDER BY Cost + 0 $_REQUEST[sort]";
That only works for one Ascending, how can I make sure they all work correctly?

My database table: Cost varchar(11)
This topic has been closed for replies.

3 replies

Inspiring
June 12, 2008
The_FedEx_Guy wrote:
> Hi Steve,
> Its still giving me the same problem. I've just change the table:
> ALTER TABLE `property` CHANGE `Cost` `Cost` DECIMAL( 9, 2 ) NOT NULL DEFAULT '0.00'

I'm no PHP expert, so can't tell where in the code your going wrong. To
make sure mySQL is behaving, do you have access to an online admin
screen? Can you recreate the query in that and see if its behaving as
expected?

Steve
Inspiring
June 12, 2008
Hi Steve apologies, my server has a few copies of this website and the db connection was pointing to the wrong one.
Its been amended now and works a treat.

Thanks
Inspiring
June 12, 2008
The_FedEx_Guy wrote:
> I am trying to process information and want to order it by price. I have a form
> to choose to show the price ascending or decending.
>
> I'm getting values like this:
> ?79,950.00
> ?52,500.00
> ?164,950.00
> ?14,500.00
>
> The prices are stored in my database like this: 52500.00
>
> My SQL statement is:
>
> $query_results = "SELECT *
> FROM property
> WHERE B_R = 'BUY'
> AND Accepted = 'Yes'
> AND (City = '$_REQUEST
quote:

' Or Postcode = '%$_REQUEST
quote:

' Or Area =
> '$_REQUEST
quote:

')
> AND NoBeds $NoBeds
> AND Cost BETWEEN $_REQUEST[minPrice] AND $_REQUEST[maxPrice]
> ORDER BY Cost $_REQUEST[sort]";
> I tried ORDER BY Cost + 0 $_REQUEST[sort]";
> That only works for one Ascending, how can I make sure they all work correctly?
>
> My database table: Cost varchar(11)

Cost should be decimal(9,2), not varchar(11), thats why its not ordering
correctly.

Steve