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

lekvarnik’s picture

Any advice how to sort Views PHP fields asc?

K.MacKenzie’s picture

I 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

kreynen’s picture

Using http://drupal.org/project/devel you can dsm() the output instead of print_r

tylerfrans’s picture

Does 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.

vishnumodi1987’s picture

Title: Unable to sort $row1->php and $row2->php. Possibly bug. » Unable to sort using global php code
Assigned: lekvarnik » vishnumodi1987

I 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.

dpearcefl’s picture

Assigned: vishnumodi1987 » Unassigned

Unless 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.

Delphine Lepers’s picture

Maybe your problem is the same as here : http://drupal.org/node/1178170#comment-6032566

rohankumar.1524’s picture

Issue summary: View changes

I have same issue like that, anyone has got answer. I have tried https://www.drupal.org/node/1178170 but no success from this.

DIMSKK’s picture

Okay 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:

print $value;
liam morland’s picture

Priority: Critical » Normal
Status: Active » Closed (outdated)

If this applies to a later version, please re-open and update the version.