mySQL error when the select statement is dynamically sent

A

Anonymous

Guest
I am getting...

"You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1"

when I run mysql_query if the select statement is built on the fly (ie. $mySQL = "select * from plans where age_id in ($ageList) and deductible_id in ($deductibleList) and type_id in ($typeList)"; )

but if i hard code the result I get if i just echo the above statement it works just fine.

(one that works) $mySQL = "select * from plans where age_id in ('5') and deductible_id in ('1') and type_id in ('1','4','2','3','5')

Thanks in advance
 
Correct query would be

$mySQL = "select * from plans where age_id in ('5') and deductible_id in ('1') and type_id in ('1,4,2,3,5')


Thanks

Vikas Garg
http://www.phpdir.com/
 
php-vikas said:
$mySQL = "select * from plans where age_id in ('5') and deductible_id in ('1') and type_id in ('1,4,2,3,5')

I'd just like to point out that using IN instead of = when you just have a single possible "correct" value (e.g. '5' or '1') is a waste of CPU cycles.

Code:
SELECT * FROM plans WHERE age_id = '5' AND deductible_id = '1' AND type_id IN ('1,4,2,3,5');
 
Thanks php-vikas

That did the trick... I swear I tried the before but I guess not.


swirlee that is a good point, but all three have the possiblity of being a list in my application.

Thanks again
 
Back
Top