You should name your fields as arrays, by adding square brackets after the field's name, like this:
PHP Code:
<textarea name="comment_text[]" rows=3 cols=40></textarea>
<input type="hidden" name="post_id[]" value="<?= post_id;?>" />
When your form is posted, you can loop through the arrays like this:
PHP Code:
$posts = $this->input->post('post_id'); //returns an array!!
$comments = $this->input->post('comment_text'); //also returns an array
foreach ($posts as $key=>$post_id) {
if (empty($comments[$key]) continue; //don't save empty comments fields
$data = array(
'post_id' => $post_id,
'comment' => $comments[$key]
);
$this->db->insert('table',$data);
}