I suppose to get a string from my database that looks like that:
6841819,6595747,6597673,6696253,6616167,6616197,6611931,6600475,6760303,6748661
Then I need to separate the string using explode() , and to implode again to build a sql query string.
There's my array like this after explode() :
Array
(
[0] => 6841819
[1] => 6595747
[2] => 6597673
[3] => 6696253
[4] => 6616167
[5] => 6616197
[6] => 6611931
[7] => 6600475
[8] => 6760303
[9] => 6748661
)
And my codes:
$sql = "select * from table where id like %0001% or id like %";
$explode = explode(",", $array);
$implode = implode(" or id like %", $explode);
$sql.= $implodevno."<br>";
echo $sql;
And the output sql query which is incorrect because it missed a '%' at the end of each value:
select * from table where id like %0001% or id like %6841819 or id like %6595747 or id like %6597673 or id like %6696253 or id like %6616167 or id like %6616197 or id like %6611931 or id like %6600475 or id like %6760303 or id like %6748661
I can't find solutions to add a '%' behind using implode(), any solutions or better way to do this ?
The correct output should be:
select * from table where id like %0001% or id like %6841819% or id like %6595747% or id like %6597673% or id like %6696253% or id like %6616167% or id like %6616197% or id like %6611931% or id like %6600475% or id like %6760303% or id like %6748661%