Forums

Building advanced filter with where statement in php

matcarls 15 Nov, 2019
Hi

I have the code below in my CC6 where conditions rules list for a db reader. My Model name is "modhead" for a table named deliveryheads. The interesting column name for this question is contactno. I want to get the logged in users group-names. Pick out the first chars before _ (this is the contactno for the logged in user) and use that in a sql statement. Everything except returning the correct array works below. I would expect CC to interpret it all into "where contactno in (123,456,789)".
My question is what to return to create such sql-statement?
<?php
$user = JFactory::getUser();
$groups = $user->get('groups');
$db = JFactory::getDBO();
$elm = array();

foreach ($groups as $group)
{
$db->setQuery($db->getQuery(true)
->select('title')
->from("#__usergroups")
->where("id" . ' = ' . $group)
);

$groupsdb = $db->loadRowList();

foreach ($groupsdb as $groupdb) {
$contact = substr($groupdb[0],0, strpos($groupdb[0], '_'));
if ($contact)
{
array_push($elm, $contact);
}
}

}
$return = array('modhead.contactno/in:' => $elm);
return $return
?>
Regards
Mattias
matcarls 18 Nov, 2019
Hello !?

Please give me some advice on what to return from php to build a proper sql where statement. I have been searching these forums for more than two whole days and is still stuck.
Found "How do I build a WHERE statement in CCv5?" and thought it would lead me somewhere, but it seems to not be correct for CC6. Also read "CHRONOFORMS V6 MANUAL" which says close to nothing about php and filtering. Just that it is possible. and still with shortcodes in it.
Right now I only got this part in the php. I want to use the above. But I just dont now what to return. My column in the db is contactno and I want records where contactno=1235 (it is an int in the db).
<?php
return array('modhead.contactno' => '1235');
?>
And what I get with above is:

This is the top of the data reader:


Any help, please !
healyhatman 19 Nov, 2019
Can't use shortcodes in PHP, if that helps you. If you're using PHP to create a filter you might as well take the next step and just use PHP to read the data.
https://docs.joomla.org/Special:MyLanguage/Selecting_data_using_JDatabase
This topic is locked and no more replies can be posted.