Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6339099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:34:54+00:00 2026-05-24T19:34:54+00:00

I want to be able to put ‘or’ condition inside a foreach loop when

  • 0

I want to be able to put ‘or’ condition inside a foreach loop when defining pagination variable at the controller like below:

foreach($p as $ps){
$this->paginate = array(
                'or' => array(
                    array('Petition.commune_id LIKE' => $commune_ids['Commune']['id'] . ","),

                    ),Recipe
                'limit' => 10
            );

}

I know above is wrong but I’ve compiled the codes for demonstration purposes. Is there a way we can do this in cake?

I need to loop because I want to be able to use ids from another table (which has been fetched as an array by find method) and use this for looping in the current table which is Petitions table. $commune_ids[‘Commune’][‘id’] is what I need to loop through as or value. Alternatively the query will be like:

SELECT * FROM petitions WHERE commune_id = 971 OR commune_id = 123 OR commune_id = 321 OR commune_id = 432 

but of course I can do this in find function but I would like to paginate this results…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T19:34:54+00:00Added an answer on May 24, 2026 at 7:34 pm

    What you want is the query:

    SELECT * FROM petitions WHERE commune_id IN (971, 123, ...)
    

    In Cake, that’s:

    'conditions' => array(
        'Petition.commune_id' => array(971, 123, ...)
    )
    

    So you make an array of ids which you can put into the condition. Done.

    $communeIds = /* assemble array somehow */;
    
    $this->paginate = array(
        'conditions' => array(
            'Petition.commune_id' => $communeIds
        ),
        'limit' => 10
    );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to be able to put certain configuration information in my settings.py file
I am using Eclipse 3.4. I want to be able to put a breakpoint
I have a list in which i want to be able to put different
I want to be able to put preformatted text (i.e. containing line breaks) into
I want to have a background image and being able to put LabelField ,
I want to be able to put about 3k documents into memcached each time
I want to be able to put PHP into the database and run it.
Is it able to put views to the left, but off-screen? I want display
I want to be able to put an object into one of several shards
I have a javascript that I want my users to be able to put

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.