CakePHP 3.6: fetchAll()with conditions

23
October 11, 2018, at 4:50 PM

I would like to add search functionality in my view. The problem is that I get data from raw sql like this so I dont know how to filter the results:

        $conn = ConnectionManager::get('default');
        $stmt = $conn->execute('SELECT c.id as customerid, CONCAT(c.name, " ", c.surname) as customer, s.title as title, s.length, cs.created , DATE_ADD(cs.created, INTERVAL s.length DAY) as expiring_date, DATEDIFF(DATE_ADD(cs.created, INTERVAL s.length DAY), NOW()) as days_left
                                FROM customers c 
                                JOIN customer_service_types cs on c.id = cs.customer_id
                                JOIN service_types s on cs.service_type_id = s.id
                                WHERE s.is_subscription = 1 and DATE_ADD(cs.created, INTERVAL s.length DAY) > DATE_ADD(NOW(), INTERVAL -30 DAY)
                                ORDER BY expiring_date');
        $expiringServices = $stmt->fetchAll('assoc');
        //debug($expiringServices,true);
        $this->set(compact('expiringServices'));

Is it possible to filter the results by a form input? I want the user to filter the results by entering the name in a text field and compare it with customer field which returns from the sql query. One guess is the fetchAll(PDO::FETCH_FUNC, fun_name) but I dont know how to implement it.

READ ALSO
echo not printing after form block [duplicate]

echo not printing after form block [duplicate]

This question already has an answer here:

14
Php mysql insert/update from json

Php mysql insert/update from json

hello i have a problem insert data to mysql working but i need if not exist data create if exist update all rowNow after each refresh page add same data but not updating

25
$_POST is empty in push notification response (PHP)

$_POST is empty in push notification response (PHP)

Can anybody tell me how to get the response data from a push notification responseI am currently only able to get data from headers, but $_POST is an empty array

48