Use a comma-separated field in another SQL query I was just wondering if there was a better way to write this block of code in php. I have a string with values separated by commas. I need to prepare that string to pass it on to the query using IN clause. 

 $sql = "SELECT domain, items FROM rep_skills WHERE report_id = $id ";
 $data = $conn-&gt;query($sql)-&gt;fetch_object();

 while($data){
     // can this be done in one line? 
     $array =  explode(",",$data-&gt;items); // string here is 39,40,41
     $items = implode("','",$array);  // string here is 39','40','41
     // end of block

     $result = $conn-&gt;query("SELECT description 
           FROM ".$tables[$data-&gt;domain]." 
           WHERE item_id IN ('".$items."')");

     $description = '';
     while($row = $result-&gt;fetch_object()){
        $details .= '- '.$row-&gt;description;
    }
}
It's a very weird database schema in the first place.

There should be never a thing like comma-separated values in one cell. Learn the database normalization and then create a link table wghich can be used to get all your records in a single query with JOIN.

There should be never a thing like multiple tables of the same structure. there should be only one table with a field to distinguish the kind of domain.