简体   繁体   中英

SQL : Unknown column in 'where clause'

I have a code :

$id=implode(",",$selected);

$query = "SELECT u.id, p.brand, n.number FROM `user` u 
LEFT OUTER JOIN `phone` p ON u.id = p.id LEFT OUTER JOIN `number` n 
ON p.id = n.id WHERE u.id in ($id)";

Where $selected is an array array(1,2,3) . But when i run it, it appears this notice :

Unknown column '1' in 'where clause'

How to handle this problem? Thank you

Here you can do it like :

$id = implode("','",$selected);

This query will run :

$query = "SELECT u.id, p.brand, n.number FROM `user` u LEFT OUTER JOIN `phone` p ON u.id = p.id LEFT OUTER JOIN `number` n 
ON p.id = n.id WHERE u.id in ('$id')";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM