0

I want to know how can I check The specific order id are in the user database

the order_id column have multiple data like this: 1,2,3,4,5 each user have a unique id

I don't know how to do this and get the user data based on the specific order id

so the example I have a specific order id, let's say 5

and I want to know which user that have order id 5

I have tried with SQL LIKE Operator and SQL IN Operator, but it doesn't work

$userdata = $database->query("SELECT * FROM users WHERE order_id LIKE '%5%'")->fetch_assoc();
$userdata->order_id; //show 1,2,3,4,5

user table

user_id | order_id
1       | 1,2,3,4,5
2       | 6,7,8,9,10
3       | 11,12,13,14,15
4       | 16,17,18,19,20
5       | 21,22,23,24,25
  • 1
    Fix your data model. Any time you have a string of delimited values in a column, what you *probably* want is multiple records with one value in each record. Then you can just query which records have that specific `order_id`. – David Apr 12 '22 at 15:16
  • `WHERE order_id LIKE '%,5,%' OR order_id LIKE '5,%' OR order_id LIKE '%,5'`... etc. Then deal with the results in your PHP. Or, design your database properly! – miken32 Apr 12 '22 at 15:21
  • ```select user_id from user where CONCAT(',' , order_id, ',') like '%,5,%';``` – Xupitan Apr 12 '22 at 15:47

0 Answers0