0

I have a little strange question on MySql. I have table named adds and that table has places field where are stored places id. Places field value equals serialized array (e.t.c array('1', '3', '4')) of places ids'. Also i have search form and I would like to search more fields than one at once. For ex: I would like find places with ID('3', '6', '8' and so on). When i query using mysql like this it throws an error.

$val=array('3', '6', '8');
mysql_query("Select * from add where active='active' && array_intersect(unserialize(places))");

How can i do query? May it possible using stored procedures or functions in MySql?

1 Answers1

0

You should use implode to turn it into a usable string. This assumes your array of values is completely trustworthy (i.e. not from a user submitted form)

$val=array('3', '6', '8');
mysql_query("Select * from add where active='active' AND ID IN (" . implode(',', $val) . ")";

Please be aware that mysql_ functions have been removed from PHP

Community
  • 1
  • 1
Machavity
  • 30,841
  • 27
  • 92
  • 100