you use IN
clause for get record from array
<?php
$sql = 'SELECT *
FROM `table`
WHERE `id` IN (' . implode(',', array_map('232', $array)) . ')';
You can use LIKE
condition to fetch results that contain this student
id:
SELECT * FROM `event` WHERE student LIKE '%232%';
This will return you all rows that contain '232' in student
column.
But if you have an opportunity to change your table structure I would suggest you to extract student
column to a pivot table.
You could create event_student
table that would contain just two columns: event
and student
. And each row would link particular student
to a particular event
. The data could be easily extracted with a simple JOIN:
SELECT * FROM `event` e
INNER JOIN `event_student` es ON e.eventID=es.event
WHERE es.student=232;
If you store connections between student and events this way you will gain flexibility in your queries and avoid possible mistakes that may occur when using the answer suggested above. Imagine that you have a student with id 2324 or 12323. Both of them contain desired '232' string and both will match the '%232%'
pattern and lead to returning you wrong data.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.