So happy to be using the marvellous GroceryCRUD. Thank you.
When using the search function with or_where clauses, I believe the SQL query generated is not as expected because of the way the OR and AND clauses are combined.
Here is some SQL generated by DB_active_rec...
SELECT COUNT(*) AS `numrows`
FROM (`mytable`)
WHERE `myvalue` = 'x'
OR `myvalue` = 'xx'
OR `myvalue` = 'xy'
OR `myvalue` = 'yz'
AND `mysearch` LIKE 'searchvalue'
But for the filter to work properly we need to bracket the OR clauses together...
SELECT COUNT(*) AS `numrows`
FROM (`mytable`)
WHERE (`myvalue` = 'x'
OR `myvalue` = 'xx'
OR `myvalue` = 'xy'
OR `myvalue` = 'yz')
AND `mysearch` LIKE 'searchvalue'
To achieve this we can change
if (count($this->ar_where) > 0 OR count($this->ar_like) > 0) { $sql .= "\nWHERE "; } $sql .= implode("\n", $this->ar_where);
To..
if (count($this->ar_where) > 0 OR count($this->ar_like) > 0) { $sql .= "\nWHERE ("; $sql .= implode("\n", $this->ar_where); $sql .= ")"; } else{ $sql .= implode("\n", $this->ar_where); }
I suspect other clauses may be similarly affected but haven't had time to check yet.
Thank you