jigga Posted February 14, 2021 Share Posted February 14, 2021 (edited) I have a kind of search and react on my site. The user can search for a number in a column as below $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 oemnr column today can be 12345 which shows up if the user type 12.... I want to expand the oemnr column as 12345/03124/34713, 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. Edited February 14, 2021 by jigga Quote Link to comment https://forums.phpfreaks.com/topic/312147-search-for-string-in-column-in-mysql-table-separated-by-a-character/ Share on other sites More sharing options...
Barand Posted February 14, 2021 Share Posted February 14, 2021 1 hour ago, jigga said: I want to expand the oemnr column as 12345/03124/34713, numbers separated with / or another character. Don't. Put your oemnr in a separate table, one per row with the id of the parent record as a foreign key. In other words, normalize your data. +------------------+ | main_table | +------------------+ +------------------+ | id (PK) |-------+ | oem_number | | etc... | | +------------------+ +------------------+ | | id (PK) | +------<| table_id (FK) | | oemnr | +------------------+ Quote Link to comment https://forums.phpfreaks.com/topic/312147-search-for-string-in-column-in-mysql-table-separated-by-a-character/#findComment-1584455 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.