0

I have an array of six elements ($categories = array('dinner','casual','wedding')) and I would like to make a SQL query that would look like this:

SELECT * FROM produts WHERE id = /* values of array $categories... eg. (dinner || casual || wedding) */

Lei Lionel
  • 1,243
  • 11
  • 19

2 Answers2

1

Try this:

$conditions = '';

foreach($categories as $cat) {
    $conditions[] = " id = '".$cat."'";
}

$sql = 'SELECT * FROM produts WHERE '.implode(" OR ", $conditions);
Object Manipulator
  • 8,644
  • 2
  • 10
  • 31
-1

You must to use IN instead WHERE.