Forums

how to make two commands work together in WHERE SQL

medaacek 21 Feb, 2013
Can anybody help me please? Bob Im sure you know the answer! Following your templates I used the two snippets in two forms - one for filtering only records with value "2" and the other to make filter input/submit command for the table. When I tried to combine these two, it fails - is it possible to combine these two snippets (below) together in WHERE SQL filed of the CC?
As it is now, it only shows records with "2" but after dynamic filter is applied, it brings up error saying that the second syntax is somehow wrong.


WHERE `availability_calendar_units_id` = 2

<?php
$title = JRequest::getString('title', '', 'post');
if ( $title ) {
echo " WHERE `title` LIKE '%$title%' 
OR `enddate` LIKE '%$title%'
OR `startdate` LIKE '%$title%'
OR `description` LIKE '%$title%' ";
}
?>


Thank you for help!
Jiri
GreyHead 22 Feb, 2013
Hi Jiri,

I'd do it like this:
<?php
$where = array();
$where[] = '`availability_calendar_units_id` = 2';
$title = JRequest::getString('title', '', 'post');
if ( $title ) {
  $where[] = "(`title` LIKE '%$title%'
    OR `enddate` LIKE '%$title%'
    OR `startdate` LIKE '%$title%'
    OR `description` LIKE '%$title%')";
}
$where = implode(' AND ', $where);
echo ' WHERE '.$where;
?>

Bob
medaacek 22 Feb, 2013
Many thanks Bob,
At the moment Im experimenting with CC V4 which seems to be more user-friendly for people like me, who do not have enough coding experience. With CC V2 I had also troubles that after submitting the search query the CC link lost connection to its menu item...nevertheless after trying both versions, V4 seems to work better for my needs.

Thanks again!

Jiri
This topic is locked and no more replies can be posted.