Excluding a list of dates from a query

I think I’m close, but something isn’t quite right. I really miss being able to use “”. Things were simpler!

Anyway, I’m building a list of DATES from one query:

[php] while($mydates = mysql_fetch_array($gd)) {
$ddates = $ddates.’,’’.$mydates[‘startdate’].’’’; }[/php]

If I echo $ddates, I’m seeing what I think I’m should be seeing:

‘2010-01-01’,‘2013-01-05’,‘2013-01-06’

In my second query, I need to EXCLUDE this list of dates from the result, so I’ve got this:

[php]…AND startdate NOT IN ($ddates)[/php]

Ain’t working. However, if I take the $ddates echo output and place that in the query instead:

[php]…AND startdate NOT IN (‘2010-01-01’,‘2013-01-05’,‘2013-01-06’)[/php]

This DOES work.

What am I missing?

TIA

What error are you getting?

No error message - it’s just not excluding the dates…

If it works manually there must be something wrong in your string generation. Perhaps post the full code (section) and table structure?

I would personally use an array/implode to build the string

[php]
$ddates = array();
while($mydates = mysql_fetch_array($gd)) {
$ddates[] = $mydates[‘startdate’];
}
echo “NOT IN (’” . implode("’,’", $ddates) . “’)”;
[/php]

The below worked perfectly! Thanks!
Primarily a Cold Fusion guy, I still don’t quite grok implode and explode. Need to read up a little more.

[php]
$ddates = array();
while($mydates = mysql_fetch_array($gd)) {
$ddates[] = $mydates[‘startdate’];
}
echo “NOT IN (’” . implode("’,’", $ddates) . “’)”;
[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service