Search for string using LIKE in column in mysql table separated by a character

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
New php-forum User
New php-forum User
Posts: 1
Joined: Sun Feb 14, 2021 12:53 am

Sun Feb 14, 2021 1:38 am

I have a kind of search and react on my site. The user can search for a number in a column as below

Code: Select all

$search = mysqli_real_escape_string($link, $_POST["query"]);

$query = "SELECT * FROM $table[$i] WHERE oemnr LIKE '".$search."%' ORDER BY model";

The code works fine but I want to expand the function to get match for other numbers also. The column oemnr can be 12345 which shows up if the user type 12.... 

I want to expand the oemnr column as

12345/03124/34713, i.e. numbers separated with / or another character.

If the user type 03... or 34... I want to find and show 12345 because it is on the same row and corresponds to the numbers on the same row. Is it possible to do in mysql? In php that kind of operation can be done with the explode function but I don't know how to use with mysql.
Post Reply