Split an array of ids and save it as individual rows in table I managed to get all ids from a table using query in drupal. I got the array of ids. I'm struggling to insert all the ids in another table as individual rows. As Im new to the drupal concepts,its very difficult for me to figure it out. Any help is appreciable.:)
You can use db_insert in your module OR drupal_write_record

E.g: drupal 7 code



 //Assuming your array is like
 /*
   $ids = array(1,2,3,4,5,6,....);
 */

  // Traversing ids by using foreach loop
  foreach($ids_array as $key=>$value){
       $custom_table_data = array(
            'id'=>$value,// id value
            'column1'=>'..'
        );

       // INSERT INTO {table_name} (field_1, field_2, ...) VALUES ('ABC', '123', ....)
        $nid = db_insert('table_name') // Table name no longer needs {}
        ->fields($custom_table_data)
        ->execute();

        // OR using drupal_write_record... 
        drupal_write_record('table_name', $custom_table_data);
  }