Platon Technologies
neprihlásený Prihlásiť Registrácia
SlovakEnglish
open source software development oslavujeme 10 rokov vývoja otvoreného softvéru! Streda, 25. november 2026
O nás
Magazín
Otvorený softvér
CVS
Služby
Index  »  Projekty  »  phpMyEdit  »  Fórum  »  I want a numeric sort, not a string sort

phpMyEdit General     I want a numeric sort, not a string sort
Odoslať novú tému   Odpovedať na tému    
 
ian@lljproperty.com     Založený: 26.02.2006   Príspevky: 1  
Príspevok Zaslal: 2006-02-26 21:54
Návrat hore  Odpovedať s citátom     

I have two tables (1) invoice (key is id which is the invoice number) and (2) invoice_details (key is id and invoice_id is a foreign key to invoice).

In the PME for the invoice_details I have the following entries:

$opts['sort_field'] = array('invoice_id', 'id');

$opts['fdd']['id'] = array(
'name' => 'ID',
'select' => 'T',
'options' => 'AVCPDR', // auto increment
'maxlen' => 10,
'default' => '0',
'sort' => true
);
$opts['fdd']['invoice_id'] = array(
'name' => 'Invoice',
'select' => 'T',
'maxlen' => 11,
'required' => true,
'sort' => true
);

$opts['fdd']['invoice_id']['values']['table'] = 'llj_invoice';
$opts['fdd']['invoice_id']['values']['column'] = 'id';
$opts['fdd']['invoice_id']['values']['description']['columns'][0] = 'id';
$opts['fdd']['invoice_id']['values']['description']['columns'][1] = 'inv_dt';
$opts['fdd']['invoice_id']['values']['description']['columns'][2] = 'comments';
$opts['fdd']['invoice_id']['values']['description']['divs'][0] = ' ';
$opts['fdd']['invoice_id']['values']['description']['divs'][1] = ' ';
$opts['fdd']['invoice_id']['values']['filters'] = " delete_flag = 'No' ";
$opts['fdd']['invoice_id']['values']['orderby'] = ' -id ';

My problem is that the List screen for invoice_details is ordered by string rather than by number so invoice 10 is displayed before invoice 2.

Any suggestions for a way around this?

 
michal     Založený: 17.06.2003   Príspevky: 537   Bydlisko: Slovakia
Príspevok Zaslal: 2006-03-01 10:52
Návrat hore  Odpovedať s citátom     

maybe
'select' => 'N'
(but i think that is only for filters)

 
techno_blaster     Založený: 19.01.2007   Príspevky: 7  
Príspevok Zaslal: 2007-01-19 21:35
Návrat hore  Odpovedať s citátom     

Hello All! Newbie here....

When trying to sort my columns by clicking the column header, the data appears to be string sorted instead of numeric. Since I have numbers in these fields, the sort is incorrect.

I noticed the original thread questioned this issue, but there was no resoution.

How do I make the column sort the numeric data properly? I already have the option set as follows on al my numeric fields.

$opts['fdd']['LoanBalance'] = array(
'name' => 'LoanBalance',
'select' => 'N',
'maxlen' => 10,
'default' => '0.00',
'sort' => true,
'total' => sum,
);


Anyone else encounter this problem who may have a solution??

 
michal     Založený: 17.06.2003   Príspevky: 537   Bydlisko: Slovakia
Príspevok Zaslal: 2007-01-23 13:30
Návrat hore  Odpovedať s citátom     

sorting is done on sql level, so it is sorted as your db thinks it should be sorted. check whether the column is varchar or int.

 
techno_blaster     Založený: 19.01.2007   Príspevky: 7  
Príspevok Zaslal: 2007-02-03 21:31
Návrat hore  Odpovedať s citátom     

Michal: You are correct! My data was varchar. I changed it to type=dec and it sorts correctly now! Thanks...


michal Napísal:
sorting is done on sql level, so it is sorted as your db thinks it should be sorted. check whether the column is varchar or int.


 
rlugo     Založený: 18.12.2007   Príspevky: 4  
Príspevok Zaslal: 2007-12-23 20:06
Návrat hore  Odpovedať s citátom     

I am trying to sort this alphanumeric data:

1000MB
100MB
12MB

Into this:

12MB
100MB
1000MB

I tried hacking the phpmyeditclass with this:
...
if ($parts['orderby'] != '')
$ret .= ' ORDER BY CAST('.$parts['orderby'].' AS UNSIGNED),'.$parts['orderby'];
...

but I get the following error:

MySQL error 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '`PMEtable0`.`Id` AS UNSIGNED),`PMEtable0`.`Web Space`,`PMEtable0`.`Id` LIMIT 0, ' at line 1

 
apollobc     Založený: 18.08.2009   Príspevky: 8  
Príspevok Zaslal: 2009-08-18 07:39
Návrat hore  Odpovedať s citátom     

Fix (HACK) for numerical sort

Search/Find (~Line # 598)/phpMyEdit.class.php

Kód:
$ret .= ' ORDER BY '.$parts['orderby'];


Change To
Kód:
$ret .= ' ORDER BY '.$parts['orderby'].'+0';


Does not appear to affect other searches?[/code]

 
Odoslať novú tému   Odpovedať na tému    

Copyright © 2002-2006 Platon Group
Stránka používa redakčný systém Metafox
Na začiatok · Odkazový formulár · Prihláška
Upozorniť na chybu na PLATON.SK webstránke · Podmienky použitia · Ochrana osobných údajov