Reputation: 3165
How should a specific find function look in cakephp? I have this criteria: I want to search by a given code that is formed of 2 letters and 5 numbers. The two letters are the initials of the first two words in a field and the numbers are meant to match a field.
For example I have the code=PG35478
and after this I want to find the user that in his name field is Phillip George and has the postal code 35478.
So:
$user = $this->User->find('all', array(
'conditions' => [...?]
));
Upvotes: 0
Views: 109
Reputation: 5271
{Edited for improved SQL Injection protection}
Assuming you broke the code into its components for readability: $first_char, $second_char, $postal
Also assuming your database fields are called namefield and postalfield.
Then use this
$this->User->find('all', array('conditions' => array(
'namefield LIKE' => "'" . $first_char . "% " . $second_char . "%'",
'postalfield' => $postal
)));
There is a space after the first percent sign
Upvotes: 1