简体   繁体   中英

Mysql Regexp with array

I am getting an array of category id eg. ['1','2','3'] and in my database table it is stored as 1_abc eg : category : 1_Sameer Now it is easy if i get one value

ie. WHERE category like 1_%;

But since this is an array how can i use like or regex to compare with the database values

In this case you can do as many queries as you have array elements and merge these results together if needed to get single collection of elements.

$results = new Collection();
foreach($ids as $id) {
$categories=Category::where("id","like","$id_%")->get();
    $results=$results->merge($categories);
}

you have to do looping for that

for($i=0;$i<=count($array_result)-1;$i++) {

$result=mysql_query("select * from table_name where category like '{$array_result[$i]}_%' ");

}

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM