I'm using Views and CCK on a local intranet site to keep track of the toner levels for multiple network printers.
One of my CCK fields is a text area where I'm using the PHP input format. My code scrapes an .html page for a value and displays it for me. When viewing this data with Views, the content retrieved via this field is sorted by the PHP code itself, not what the PHP generates.
In other words, Views seems to want to sort by this:
<php etc etc query X page for Y value php>
Rather than what it returns:
11
How can this be fixed?
[Edited to add <code> and </code> tags; nevets]
Comments
Comment #1
Brentnauer commentedSide note: The PHP returns the value just fine. I think it may have something to do with Views displaying the data using ['value'] instead of ['view']... Not sure though. My PHP abilities are very limited.
Comment #2
Brentnauer commentedMy original example was hidden. Here's what I meant to show:
In other words, Views seems to want to sort by this:
< php get value X from external non-Drupal page >
Rather than what it returns:
11
Comment #3
nevets commentedViews sorts at the database level (ie ORDER BY) so for text fields with input formats, the sorting is done on the unprocessed text (PHP code in your case).
Comment #4
Brentnauer commentedIs there any way to get around this?
Comment #5
Brentnauer commentedMessing with the template code for that particular field doesn't work either... Not that it should. Not sure what I was thinking.
If anyone can provide a push in the right direction, I'd appreciate it greatly.
Comment #6
merlinofchaos commentedHow these fields are sorted and displayed are up to the module that implemented them.
Note that it is basically not possible to do a SQL sort via the results of PHP code, because SQL can't run the PHP. However, you can use computed field and place your PHP code in teh computed field and have the computed field store the results of the PHP. Then it can sort by that result, which will be in the database.
Passing this to CCK in case there's more, but I suspect this actually is all we can do on the issue, so marking it fixed.