I have an usual search form using HTML that will be extract the data from mysql (the connection is using PHP and mysqli). The function works well in searching 1 value, but I want to make user can search more than 1 value that will be separated by comma (,).
For example:
Searching 1 value works well.
But I want to search 2 or more values inside the search box, like: 42-7278954,53-1217544,07-2517487,...
I hope user can input something like in the pic below and the result will have 2 rows --> CN_no 42-7278954 and 53-1217544:
The query I have so far is:
$sql = "SELECT * FROM mock_data WHERE CN_no IN ('{$CN_no}') OR doc_no IN ('{$doc_no}')";
Notes: CN_no is "Shipment Code" and doc_no is "Reference No"
But well... it's obviously give me an error because of the incorrect syntax.
Please help me to revise it. Thank you.
======== update query based on vp_arth's answer ========
$cn = explode(',', $CN_no);
$incn = str_repeat('?, ', count($cn)-1).'?';
$doc = explode(',', $doc_no);
$indoc = str_repeat('?, ', count($doc)-1).'?';
$query = "SELECT * FROM mock_data WHERE CN_no IN ({$incn}) or doc_no IN ({$indoc})";
$result = $conn->query($query , array_merge($incn, $indoc));
But it give me an error