#1 March 3, 2018 1:33pm

neosin
Member
Registered: March 3, 2018
Posts: 1

Parser - how to to do this?

Hello
In my module I have 2 date fields and want to compare them and based on the comparison display a string instead of displaying the 2 date fields in the view.

Example:
when a user goes here http://127.0.0.1/admin/mymodule/ and they see the list of entries, in the list the 2 dates would not show. Instead it would display a string based on the comparison outcome of the two date fields.

I tried putting the code in the parser field but I can't seem to put any php in there other than simple $value = X;
also it seems not possible to reference other fields in the parser field itself.

how do I proceed?

Offline

#2 March 4, 2018 5:30pm

timbuckingham
Administrator
From: Baltimore, MD
Registered: April 2, 2012
Posts: 978

Re: Parser - how to to do this?

When running a parser it's run in function context with $item containing the full row data and $value containing the display data for the particular column of a view. I believe $item only contains what is pertinent to the view rather than the entire row from the related database table. If you need another column that isn't part of the view you'll need to call it separately, e.g.:

$record = sqlfetch(sqlquery("SELECT * FORM my_table WHERE id = '".$item["id"]."'"));
$value = $record["date_1"]." ".$record["date_2"];

That would combine the "date_1" and "date_2" columns from a table into a single column in a view.

Offline

Board footer

Powered by FluxBB

The Discussion Forum is not available on displays of this size.