Page 1 of 1

Proper Query Syntax?

Posted: Mon Jun 24, 2002 10:23 pm
by virgil
Hey PHP's (peeps? MyPHP's LOL),

This code is supposed to return event listings based on multiple months selected from a dropdown menu named "month_filter[]"from a database. With (JAN,FEB,MAR and APR) being the selected months.
//Comments are not in the actual code.

What's wrong with the "SELECT,WHERE,IN "SQL syntax? I get the error:


MySQL error 1064: You have an error in your SQL syntax near 'JAN'.'FEB'.'MAR'.'APR'')' at line 3


Code: Select all

if($date_filter!=$ALL)
{
$count = count($date_filter);

echo"$count"; //Just to test: (Returns 4)
}


if( $count > 1 )
 
   {
   $month_filter = implode( "'.'", $month_filter);

   $month_filter="'$month_filter'"; // This adds quotes at both ends

echo "$month_filter"; //Just to test:(Returns 'JAN'.'FEB'.'MAR'.'APR')



     $query="SELECT eventnum, date_year, date_month, date_day 
FROM eventpost WHERE date_year='$year_filter' AND date_month IN ('$month_filter')";
   


$result = mysql_query($query);
   
    while ($row=mysql_fetch_array($result, MYSQL_ASSOC)) etc.....

Whats wrong?

Thanks for any help.

Posted: Tue Jun 25, 2002 2:15 am
by twigletmac
You need commas not fullstops between the information in the IN() bit. Change,

Code: Select all

$month_filter = implode( "'.'", $month_filter);
to

Code: Select all

$month_filter = implode( "','", $month_filter);
Mac

Posted: Tue Jun 25, 2002 2:24 am
by roninblade
you're imploding your array with a dot , try imploding it with a comma.

Posted: Tue Jun 25, 2002 2:25 am
by twigletmac
Umm, that's exactly what I said... :roll:

Mac

Posted: Tue Jun 25, 2002 2:26 am
by roninblade
errr... i didnt see you posted before me. :D :P

Posted: Tue Jun 25, 2002 2:29 am
by twigletmac
Aah, the hazard of taking time to actually think about what you're going to say... :lol:

Mac

Posted: Tue Jun 25, 2002 5:31 am
by roninblade
yep! i fell asleep while working. :oops: :D

Posted: Tue Jun 25, 2002 7:15 am
by virgil
Worked like a charm.....Thanks again ...Don't know what I would do with out ya.... Virgil :D