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.