We have a CCK field setup called "Price" that is a text field and are attempting to sort it in ascending order in a view but it's not sorting by the total price, just by the first number in the price. How do I adjust it to sort by the entire price?

http://www.roycerealestate.net/ashland-homes-for-sale

What we've done in Views under Sort Criteria is:

Content: Text: Price (field_price) desc

I'm guessing this has something to do with the field being text and not some other type but all the properties are already entered and I'm hoping to not have to create a new field and re-enter all the values. Any idea how to sort these by true price in descending order?

Comments

dagmar’s picture

Status: Active » Fixed

Text fields are sorted using an alfabetic order, so

9987 is before than 99,99 because 8 is lower than ',' in the ascii table.

Since cck will not allow you change text by number fields, maybe you can add another price field, This time numeric float and try to do an SQL UPDATE using phpmyadmin or similar to copy this values in the database.

Anyway views is working as expected.

merlinofchaos’s picture

Prices should be stored as raw numbers and the formatting added upon display. I thought CCK had output widgets that would do that for you. You should not store your prices as strings.

In the worst case, I believe you can use the computed field module to use PHP to mark up your prices properly.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.