I am unable to sort according my field Global PHP field.
This field have values like:
1245600
1245566
1245512
1245603
And I want to sort it using this variable asc in Views to look like:
1245512
1245566
1245600
1245603
However this is not working:
return $row1->php < $row2->php ? -1 : (int)$row1->php > $row2->php;
php is the name of my fields(each one contains a vlaue e.g. 1245600 ; it is echoed not returned in fields section of views)
Nothing shows up at all, no match ;(
I am putting this code into the last textarea in sort page section without and no others sort criterias are set. I have checked asc in sort section of global: php
Where am I making mistake?
Thanks in advance.
i am using Drupal 6 and Views 3.
I have similar problems with filter, where I can not get $row->php also. I solved it using $data->... .
However, here I have to compare row 1 and row 2, so I do not know how to do it.
Is this a bug that $row is not working in sort and filter?
Or is this line wrong?
return $row1->php < $row2->php ? -1 : (int)$row1->php > $row2->php;
Comments
Comment #1
lekvarnik commentedAny advice how to sort Views PHP fields asc?
Comment #2
K.MacKenzie commentedI am having the exact same problem myself, I am unable to print_r($row1) to see what kind of variables I am working with. Subscribe
Comment #3
kreynen commentedUsing http://drupal.org/project/devel you can dsm() the output instead of print_r
Comment #4
tylerfrans commentedDoes anybody have a solution for this? I have a similar issue, where I have a php code field (I have two, that's why I'm referencing php_1 in my code example) that has an integer value and I want to sort based on that field. I have set up a sort ascending php code with the sort code:
return $row1->php_1 < $row2->php_1 ? -1 : (int)$row1->php_1 > $row2->php_1;
What am I missing?
Edit: I didn't notice this was a Drupal 6 issue, I was on Drupal7 and my issue was caused by an old version of views_php. Updating to the latest version solved my problem.
Comment #5
vishnumodi1987 commentedI am having the exact same problem myself, I want to print $row1 /$row2 for check my condition in php code. So please give me a solution.
Comment #6
dpearcefl commentedUnless you are going to provide a fix, don't change the issue assignment to yourself.
Add me to the list of folks with the same problem.
Comment #7
Delphine Lepers commentedMaybe your problem is the same as here : http://drupal.org/node/1178170#comment-6032566
Comment #8
rohankumar.1524 commentedI have same issue like that, anyone has got answer. I have tried https://www.drupal.org/node/1178170 but no success from this.
Comment #9
DIMSKK commentedOkay so if anyone is facing problem like this, solution in #7 works.
Basically this ONLY works when you calculate the value of field via "Value Code" field, return it and then print its output via "Output Code" field like:
Comment #10
liam morlandIf this applies to a later version, please re-open and update the version.