This topic is locked
[SOLVED]

 CustomQuery on the listpage (View as-Custom)

11/1/2016 11:36:39 AM
PHPRunner General questions
S
snuffi01 author

Hi,

I need to display an value on the listpage witch i cant make the ordinary sql query result.

My thoughts is to use an Custom Query" on the listpage (View as-Custom), is that possible?

I need to do something like this:


$sql = "SELECT

IFNULL(COUNT(DISTINCT(prim_cid)), 0) AS calls,

events.event_time

FROM events

INNER JOIN event_parties ON events.g_event_id = event_parties.g_event_id

WHERE (events.event_id = 9) AND (DATE(event_time) = CURDATE()) AND (LEFT(event_parties.ani, 1) = '+') AND event_parties.agent_id = $value

ORDER BY events.event_time DESC";
$rs = CustomQuery($sql);

$data = db_fetch_array($rs);

echo "Calls answered: " . $data["calls"];


The field on witch above code is used on th elistpage is called "agent_id" and i asume that i can use that value in the custom query as $value?
When trying above it doesnt work...
Is this possible, or should i do it in a other way?
/ Kristian

Sergey Kornilov admin 11/1/2016

You should not be doing echo in 'View as' Custom. You need to assign results to $value variable. Please consult the manual at http://xlinesoft.com/phprunner/docs/_view_as__settings_custom.htm

S
snuffi01 author 11/2/2016



You should not be doing echo in 'View as' Custom. You need to assign results to $value variable. Please consult the manual at http://xlinesoft.com/phprunner/docs/_view_as__settings_custom.htm


Thanks!
This is great, it actually works!

Changed the code to:



$sql = "SELECT

IFNULL(COUNT(DISTINCT(prim_cid)), 0) AS calls,

events.event_time

FROM events

INNER JOIN event_parties ON events.g_event_id = event_parties.g_event_id

WHERE (events.event_id = 4) AND (DATE(event_time) = CURDATE()) AND (LEFT(event_parties.ani, 1) = '+') AND event_parties.agent_id = $value

ORDER BY events.event_time DESC";
$rs = CustomQuery($sql);

$data = db_fetch_array($rs);

$value=$data["calls"];


Many thanks!