Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2007-01-11 19:23:47

progre55
Member
Registered: 2006-05-02
Posts: 668

Two "Sort By" Questions

I have a custom field that contains prices. When I elect to sort by that field on a list, it puts a price that is $3,000,000 ahead of a price that is $500,000 on the list becaues it is just looking at the first character. I am sure this is simple, but I can not get it to adjust.

On a suggestion I tried:

sortby=”(price + 0)”

It was suggested that this will make MySQL do a numeric sort.

Two issues: when I did it the first time I got no results. When I change it from the “name” to “custom-XX” I got results but they were all over the place.

Second, I am also looking for the capability to sort by one field (First) and then sort by another field (second) … ie look at price and then look at size …

Any guidance and suggestion would be greatly appreciated.

progre55

Last edited by progre55 (2007-01-11 19:25:31)

Offline

#2 2007-01-11 19:51:37

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: Two "Sort By" Questions

1. There is a plugin that will treat content of a custom field as a numeric value: ort_article_psort.

2. The sort attribute can take multiple arguments, see example 5 here.

But… the plugin doesn’t work with the new sort attribute. I don’t know if there is a way to combine those two.

Offline

#3 2007-01-12 03:33:40

progre55
Member
Registered: 2006-05-02
Posts: 668

Re: Two "Sort By" Questions

Els:

Thanks for the response. Your feedback and input are always greatly appreciated. If nothing else it gets me part of the way towards a solution.

Thanks again.

progre55

Offline

#4 2007-01-12 03:41:15

Mary
Sock Enthusiast
Registered: 2004-06-27
Posts: 6,236

Re: Two "Sort By" Questions

Try

sort="cast(custom_xx as decimal) asc"

Offline

#5 2007-01-12 04:58:27

progre55
Member
Registered: 2006-05-02
Posts: 668

Re: Two "Sort By" Questions

Mary:

Tried it, but it returned nothing:

This is the code I was originally using:

<code><txp:article_custom section=“listing” sortby=“custom_8” sortdir=“asc” form=“archive_posts” limit=“99999” /></code>

The above code returned results, but it based them on the first character so a larger number $5,000,000 came before $750,000.

This is the revised code per your instruction:

<code><txp:article_custom section=“listing” sort=“cast(custom_8 as decimal) asc” form=“archive_posts” limit=“99999” /></code>

This code returned no results.

Offline

#6 2007-01-13 13:35:42

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: Two "Sort By" Questions

Are you using 4.0.4? The sort attribute is new, you can’t use it in 4.0.3.

Offline

#7 2007-01-14 02:29:37

progre55
Member
Registered: 2006-05-02
Posts: 668

Re: Two "Sort By" Questions

Els:

I am using the latest version. I do not think it is the sort feature, as much as it is the attempt to get the field to sort numerically. Like I stated earlier, Iit is a field called “price” and has data formatted like $500,000. I thought it may be the dollar signs messing things up, but I removed them with no luck.

progre55

Offline

Board footer

Powered by FluxBB