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

  • SEARCH
  • Home
  • 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 8742933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:35:15+00:00 2026-06-13T11:35:15+00:00

I am trying to figure out how to make a Mysql Select with an

  • 0

I am trying to figure out how to make a Mysql Select with an OR in where Clause. By default all clauses in where statement are ANDed and after some hours of try and fail and looking the net can’t make it work. In ZF1 it would be an orWhere() but there is not in ZF2.

This is the code i have inside a AbstracttableGateway:

$resultSet = $this->select(function (Select $select) use ($searchstring) {
             $select->join('users','blog_posts.id_user = users.id',array('name'))
                    ->join('blog_categories','blog_posts.id_category = blog_categories.id', array(
                                           'cat_name'   => 'name',
                                           'cat_alias' => 'alias',
                                           'cat_image'  => 'icon'))
                    ->order('date DESC');
                    //->where("title LIKE '%" .$searchstring . "%' OR content LIKE '%". $searchstring ."%'")
            $select->where->like('content','%'.$searchstring.'%');
            $select->where->like('title','%'.$searchstring.'%');
        }
    );
    return $resultSet;

the lines with the $select->where->like are the ones that are ANDed and I want them with OR. What should I change?

  • 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-06-13T11:35:16+00:00Added an answer on June 13, 2026 at 11:35 am

    There is no orWhere in ZF2, but you could use any combination of Zend\Db\Sql\Predicate objects. For OR use 2 predicates in a PredicateSet with PredicateSet::COMBINED_BY_OR.

    There’s not much documentation for it, but you could browse the source – for now.

    Edit: sample

    use Zend\Db\Sql\Predicate;
    
    $select->where(array(
        // ...
        new Predicate\PredicateSet(
            array(
                new Predicate\Like('content', '%'.$searchstring.'%'),
                new Predicate\Like('title', '%'.$searchstring.'%'),
            ),
            Predicate\PredicateSet::COMBINED_BY_OR
        ),
        // ...
    ));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been trying to figure out how I can make a query with MySQL
I'm trying to figure out how my iOS app should work after Facebook make
I'm trying to figure out how to get a select statement to be populated
I am trying to figure out how to make my layout have the following
I'm trying to figure out how to make it so that when I'm moving
I'm trying to figure out how to make jQuery slide #content2 down and replace
I'm trying to figure out a way to make demos for a program I've
I'm trying to figure out how if there's a way to make a hostname
I'm trying to make getJSON to use JSONP object, but I can't figure out
I'm trying to figure out how to make this code work. Basically i have

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.