-2

I have an array and I wrote this code which does not work. Could someone help me with this query? Thanks a lot!

 $sql = "SELECT * FROM `product` WHERE `product`.`Productcode` IN (".$array.") ";
         $result=mysql_query($sql);
         if(!$result)die('not exist');
4

4 回答 4

1

the array should be a string

$string = implode("','", $array);
$sql = "SELECT * FROM `product` WHERE `product`.`Productcode` IN ('".$string."') ";

quotes not needed if the productcode is an integer

于 2013-06-27T09:25:03.967 回答
1

如果您的阵列不是多维的,请尝试此操作

$sql = "SELECT * FROM `product` WHERE `product`.`Productcode` IN ('".implode("',", $array)."') ";
于 2013-06-27T09:27:17.880 回答
0

You need to implode() the array to a string (presuming your $array is actually an array):

$sql = "SELECT * FROM `product` WHERE `product`.`Productcode` IN ('" . implode("', '", $array) . "')";
于 2013-06-27T09:25:11.080 回答
0

You need to implode the array to a comma separated list before it can be used IN()

IN(".implode(',',$array).")
于 2013-06-27T09:25:18.827 回答