Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#1 2008-07-04 15:53:31
- sirblackheart
- New Member
- Registered: 2008-07-04
- Posts: 7
how to sort european formated numbers that are saved in custom_fields?
The goal:
a sortable table that provides information saved in the custom_field of the articles, a link in each row brings me to the article.
What has been done:
The table works great and is sortable. It works using php reading and writing the get variables from the url, and into the sort atribute of the article_custom tag.
The problem:
Using the trick to put custom fields with numeric data in (custom_fieldx+0) it’s possible to sort this fields. The problem is, that if i have numbers in the european format with , and . Like this: 9.000,34 or 22,33 or 0,33. And I can’t find a way I could sort them the right way.
Does anybody know a wy to do this? Any help is welcome.
Thanks in advance
Gabriel
Last edited by sirblackheart (2008-07-04 16:12:13)
Offline
#2 2008-07-04 18:36:30
- uli
- Moderator
- From: Cologne
- Registered: 2006-08-15
- Posts: 4,306
Re: how to sort european formated numbers that are saved in custom_fields?
You’re probably bent for something else, but in the last resort here’s ajaxdaddy’s sorted table, whose demo works with the european number format plus sets a row selection marker to keep after sorting’s done (2nd example from above).
In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links
Offline
#3 2008-07-04 19:19:36
- sirblackheart
- New Member
- Registered: 2008-07-04
- Posts: 7
Re: how to sort european formated numbers that are saved in custom_fields?
uli schrieb:
You’re probably bent for something else, but in the last resort here’s ajaxdaddy’s sorted table, whose demo works with the european number format plus sets a row selection marker to keep after sorting’s done (2nd example from above).
Thx for the info, but you are right i’m searching for a solution with the textpattern tags or php. Because i have alreaday the jquerry tablesorter plugin running, and i just wanted to have a solution for people, that have javascript disabled. As it seams i have to possibilitys.
Just use php for getting the custom_fields, or cut the numbers appart into different customfields, like having a own custom field for the number higher tousend, and for the numbers behind the coma.
Offline
#4 2008-07-04 19:44:41
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: how to sort european formated numbers that are saved in custom_fields?
Offline
#5 2008-07-04 19:52:24
- uli
- Moderator
- From: Cologne
- Registered: 2006-08-15
- Posts: 4,306
Re: how to sort european formated numbers that are saved in custom_fields?
I was tempted to write “If all Els’ fail” but chose “in the last resort”. I knew why ;))
In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links
Offline
#6 2008-07-04 20:16:49
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: how to sort european formated numbers that are saved in custom_fields?
:)
Offline
#7 2008-07-04 20:45:08
- uli
- Moderator
- From: Cologne
- Registered: 2006-08-15
- Posts: 4,306
Re: how to sort european formated numbers that are saved in custom_fields?
Hm, blank pages for my plugin gallery, but no downloads. Looking at the source code you find a javascript that doesn’t have to do with custom fields. The URL stripped-down to mere “home” reveals an unattended site … “your call could not be connected.”
In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links
Offline
#8 2008-07-04 21:46:19
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: how to sort european formated numbers that are saved in custom_fields?
Sorry, I had not noticed that. And I now that I read the plugin thread I also notice that it didn’t seem to work with european separators.
I don’t know much about MySQL, but I can hardly imagine that this is not possible at all…
Edit: I think you can do it by entering the values like 9000.34 and 22.33, using PHP instead of the txp tag to call the custom field and do some formatting to display it as european numbers. I don’t know exactly how to do that though…
Edit again:
<txp:php>
$out = $GLOBALS['thisarticle']['name_of_custom_field'];
print number_format($out, 2, ',', '.');
</txp:php>
Instead of using the sort ‘trick’ you can also change the data type of the custom field to DECIMAL(10,2)
and just use sort="custom_1 desc"
(or asc).
Last edited by els (2008-07-04 22:56:00)
Offline
#9 2008-07-05 08:12:07
- sirblackheart
- New Member
- Registered: 2008-07-04
- Posts: 7
Re: how to sort european formated numbers that are saved in custom_fields?
<txp:php>
$out = $GLOBALS['thisarticle']['name_of_custom_field'];
print number_format($out, 2, ',', '.');
</txp:php>
Has done the job. Thx. Wouldn’t have tought it would be so easy. I tried to find more information about how to work with txp and php, but have not found tat much. Trough your post i have learned a lot.
Thx again.
Offline