hi there i want to search multiple order id in same search request on my website now my website have only 1 id search and get option like 100 or 101 but i need to search miltiple id search using comma like 100,101,102,103 and get all of those id how can do this here i share my code please help me
elseif( $_GET["search_type"] == "order_id" && $_GET["search"] ):
$search_where = $_GET["search_type"];
$search_word = urldecode($_GET["search"]);
$count = $conn->prepare("SELECT * FROM orders INNER JOIN clients ON clients.client_id = orders.client_id WHERE orders.order_id LIKE '%".$search_word."%' && orders.dripfeed='1' && orders.subscriptions_type='1' ");
$count -> execute(array());
$count = $count->rowCount();
$search = "WHERE orders.order_id LIKE '%".$search_word."%' && orders.dripfeed='1' && orders.subscriptions_type='1' ";
$search_link = "?search=".$search_word."&search_type=".$search_where;
2
Answers
Instead of using LIKE operator you can use IN operator, e.g.
WHERE orders.order_id IN (100,101,102,103)
Some important tips:
and then excute the $countQuery (always with prepared statement and parameters) and get the count immediately
You can try this code:
As you can check the code first uses the explode() method to split the search query into multiple terms separated by commas, and then it loops through each term to build the search query using the LIKE operator and the OR logical operator. The database’s matching order IDs are then looked up using the resulting query. Finally, all of the search terms are added, separated by commas, to the search query and search link.