Meghraj Suthar
Meghraj Suthar

Reputation: 43

How to get results from record by checking comma seprate values?

I want to check the records from a column where the class_id is 47, but in the class_id column there is data 49,47,24. if there is only one element in records then my query working fine but if i have multiple values and want to check with single value then its not working.

  $class_id = $_GET['class_id']; //it will bring only one at a time
  $category=mysql_query("select * from messages where class_id='".$class_id."'"); 

Upvotes: 0

Views: 40

Answers (2)

Sunil Pachlangia
Sunil Pachlangia

Reputation: 2071

You can use IN keyword.

$category=mysql_query("select * from messages where class_id IN('".$class_id."')");

Upvotes: 1

Naved Munshi
Naved Munshi

Reputation: 507

Try using find_in_set operator :

     $category=mysql_query("select * from messages where find_in_set('$class_id',class_id)"); 

Upvotes: 1

Related Questions