Jump to content

query with two IN()'s


dadamssg87

Recommended Posts

Table structure

id(int)date(date)group(int)deleted(timestamp)rate(decimal(6,2))

 

12011-12-1420000-00-00 00:00:0099.99

 

 

22012-01-1920000-00-00 00:00:00149.99

 

 

32012-07-2830000-00-00 00:00:00249.99

 

42012-03-0350000-00-00 00:00:0049.99

 

I'm receiving an array of group id's and dates. I'm imploding them and separating them by commas to form strings. I'm trying to write a query that only pulls up rows that have groups that are in the group string and dates that in the dates string.

 

<?php

   $groups[] = 2;
   $groups[] = 5;

   $dates[] = "2011-12-14";
   $dates[] = "2011-12-15";
   $dates[] = "2011-12-16";
   $dates[] = "2012-03-03";

   $groups = implode(',', $groups);
   $dates  = implode(',',$dates);

  $query = "SELECT * FROM `Exceptions` where `group` in($groups) AND `date` in($dates) AND deleted = '0000-00-00 00:00:00'";
?>

 

This query results in zero rows. I'm expecting to get get row 1 and row 4.

 

Anybody know what i'm doing wrong?

Link to comment
https://forums.phpfreaks.com/topic/252894-query-with-two-ins/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.