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,263
  • 13
  • 20

2 Answers2

1

Try this:

$conditions = '';

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

$sql = 'SELECT * FROM produts WHERE '.implode(" OR ", $conditions);
Indrasis Datta
  • 8,692
  • 2
  • 14
  • 32
-1

You must to use IN instead WHERE.