Multiple where

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
thesimon
Forum Commoner
Posts: 40
Joined: Sun Mar 13, 2005 9:44 pm

Multiple where

Post by thesimon »

how do you specify 2 where criteria when selecting from mySQL?

Cheers,
Simon
Last edited by thesimon on Thu Mar 17, 2005 12:02 am, edited 3 times in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

use the combining operators.. such as OR and AND..


Moved to Databases.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

this is how i usually end up adding a where clause to a query...

Code: Select all

// $this->_where : property
    // $where : optional parameter
    // $q1: the complete query

    if (!empty($this->_where))
    {
      if (!empty($where))
      {
        $where = "($where) AND ($this->_where)";
      }
      else
      {
        $where = $this->_where;
      }
    }
    
    if (!empty($where))
    {
      $q1 .= " WHERE $where";
    }
Post Reply