How to QQ::OrderBy alphanumeric

thread: 8 messages  |  last: about 5 months ago  |  started: wednesday, march 10, 2010, 9:53 am pst


#1  |  Gaspar Attila (Odorheiu Secuiesc, RO) Romania
Wednesday, March 10, 2010, 9:53 AM PST

There is a way to order values in alpahnumeric order using QQ::OrderBy()?

With SQL syntax which worked for me:


SELECT * FROM table ORDER BY table.field+0;

Can anyone help me to implement this with QQ:Orderby()?


Thank you.

#2  |  Patrick Ranger (Montreal, Qc) Canada
Wednesday, March 10, 2010, 10:32 AM PST

Gaspar,

Please start with the example sites where you will find an example of the QQ:Orderby clause. Don't forget to look at the source code by clicking “View source” in the top right corner. Let me know if you have any questions after.

-Patrick

#3  |  Patrick Ranger (Montreal, Qc) Canada
Wednesday, March 10, 2010, 10:47 AM PST

(I guess I messed up navigating tabs while answering... please ignore this post)

#4  |  Gaspar Attila (Odorheiu Secuiesc, RO) Romania
Wednesday, March 10, 2010, 11:50 AM PST

Nope.
Thank you anyway Patrick.

My problem for example, how can I get the following order?

35
47
98
102
210

from

102
35
98
210
47

with QQ::OrderBy() because QQ::OrderBy accept only QQNode as parameter, and QueryBuilder generated SQL contains " ORDER BY `t0`.`field` " but what I need is: " ORDER BY `t0`.`field`+0 “

How to tell QQ::OrderBy to add '+0' to field name.


Edit: My filed type is varchar.


Attila

#5  |  Patrick Ranger (Montreal, Qc) Canada
Wednesday, March 10, 2010, 12:23 PM PST

In that case I see only 2 options :
- Convert your field to integer so that it gets sorted on the numeric value

or

- Make sure your records all have the same lenght by adding leading zeros. You can run an update query to add leading zeros so that it gets sorted properly.

Does that make sense?

-patrick

#6  |  Patrick Ranger (Montreal, Qc) Canada
Wednesday, March 10, 2010, 12:29 PM PST

Oh and one more option would be to build a custom query and with your ORDER BY `t0`.`field`+0. I guess that's what you were looking for.

#7  |  Mike Ho (Sunnyvale, CA) United States of America Qcodo Administrator
Wednesday, March 10, 2010, 9:35 PM PST

Yeah, unfortunately QQ constructs do not support custom fields like this in the OrderBy clause... but in truth, I would strongly suggest that you reconsider your order-by column.  Having integers stored in a varchar that you specifically need to order against is not just a kludge, but it's quite inefficient from a performance standpoint.

#8  |  Gaspar Attila (Odorheiu Secuiesc, RO) Romania
Saturday, April 3, 2010, 4:48 PM PDT

Sorry for the late answer, my field contains strings and numbers because in this field I store product sizes. Finally I bulit a custom query as Patrick suggested.

Thank you!

Attila



Copyright © 2005 - 2010, Quasidea Development, LLC
This open-source framework for PHP is released under the terms of The MIT License.