Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Price not decending or ascending properly

Participant ,
Jun 12, 2008 Jun 12, 2008
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)
TOPICS
Server side applications
226
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 12, 2008 Jun 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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jun 12, 2008 Jun 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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 12, 2008 Jun 12, 2008
LATEST
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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines