Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

180
Views
How can I fetch records from mysql table in cakephp 3.0 with OR condition?

I want to fetch records from table for names starting with a, b or c but with status=pending in cakephp 3.0. I am trying below query. Please check what is wrong with it as it is also fetching results starting with name 's':

$this->loadModel('DbArtists');
/*** fetching records alphabetically ***/
$artists_q = $this->DbArtists->find()->where(['album_status' => 'pending'])->orWhere(['name ' => 'A%', 'name ' => 'B%', 'name' => 'C%']);
$artist = $artists_q->all();
echo "<pre>";print_r($artist);die;
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Do like below:-

$artists_q = $this->DbArtists->find()->where([
    'album_status' => 'pending',
    'OR' => [['name LIKE' => 'A%'],['name LIKE' => 'B%'],['name LIKE' => 'C%']],
]);

Or you can chek once this too:-

$query = $articles->find()->where(['album_status' => 'pending'])
->orWhere(['name LIKE' => 'A%'])
->orWhere(['name LIKE' => 'B%'])
->orWhere(['name LIKE' => 'C%']);

Reference:- https://book.cakephp.org/3.0/en/orm/query-builder.html

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!