Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how i print strings in implode function

Tags:

php

mysql

$color is array

$sql=" SELECT * FROM products  WHERE color IN (".implode(',', $color).")";

its showing result is

SELECT * FROM products WHERE color IN (red,green,blue);
SELECT * FROM products WHERE color IN ('red','green','blue');
like image 417
bhuppi choudahry Avatar asked Jul 20 '26 03:07

bhuppi choudahry


2 Answers

Update your query like as

$sql="SELECT * FROM products  WHERE color IN ('".implode("','", $color)."')";
                                           //^^         ^^  ^^          ^^ Added
like image 181
Narendrasingh Sisodia Avatar answered Jul 21 '26 20:07

Narendrasingh Sisodia


Try this:

$sql = "SELECT * FROM products  WHERE color IN ('".implode("','", $color)."')";
like image 30
Sergey Khalitov Avatar answered Jul 21 '26 18:07

Sergey Khalitov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!