0

I have field order in my content type, in which I have assigned numeric values for my 21 products in order to sort them in ascending order. Results should be displayed like the below order as I expect:

1
2
3
4
5
6
7
8 and so on to 21.

But products are displaying in the following order:

1
10
11
12
13
14
15 up to 19 then 
2
20
21
3
4
5
6 up to 9

I dont know why. Here is my snippet.

 $query = new EntityFieldQuery();
 $query->entityCondition('entity_type', 'node');
 $query->fieldOrderBy('field_order', 'value', 'ASC');
 $query->entityCondition('bundle', 'my_content_type');
 $query->pager(8,0);
 $query->propertyCondition('status', 1);
3
  • What's the type of field_order? Because it looks like it's string, not int, and here you go. Strings are sorted alphabetically., and that's exactly what you got. May it be the case?
    – Mołot
    Commented Jun 29, 2015 at 7:09
  • its a text field
    – nomeer
    Commented Jun 29, 2015 at 7:11
  • 2
    Then you got exactly proper results for the field you used - alphabetical sort. Make it Integer and you are good to go. See here if you can't see Integer field type.
    – Mołot
    Commented Jun 29, 2015 at 7:13

1 Answer 1

0

I can't make Molot's comment an answer, but I'll post one for posterity (and to close out this question).

The issue involves your data field type, integer vs. string. When the field is a string, sorting in SQL query will place the rows in lexicographic order, where the first character value is given precedence. When the field is an integer, sorting in SQL query will place the rows in numeric order, where the entire value of the number is used.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.