Welcome Guest, Not a member yet? Register   Sign In
how can i get the particular post id in foreach loop
#12

(This post was last modified: 08-10-2015, 12:38 PM by Wouter60.)

Quote:Is there any chance to submit the comment in ajax 
Sure, in order to do that, first alter this line:
PHP Code:
echo form_input('post_comment[]',NULL,'size="40" class="ta-comment"'); 
 into:
PHP Code:
echo form_input('post_comment[]',NULL,'size="40" class="ta-comment" postid="' $row->post_id '"'); 

Then, in the script section, make the following changes:

Code:
<script>

$('.ta-comment').keypress(function(event) {
  if (event.which == 13 ) {
    event.preventDefault();
    url = "<?= base_url();?>regcheck/ajax_comment_insert";
    ctext = $(this).val();
    postid = $(this).attr('postid');
    $.ajax({

      url : url,
      type: "POST",
      data : { comment: ctext, post_id: postid }
    });
  } 
  
});  

</script>

And finally, you need to add a new method to your controller Regcheck, to make it insert the posted comment:

PHP Code:
public function ajax_comment_insert()
{
  $data = array(
   'post_id' => $this->input->post('post_id'),
   'comment' => $this->input->post('comment')
  );
  $this->db->insert('post_comments',$data);

Reply


Messages In This Thread
RE: how can i get the particular post id in foreach loop - by Wouter60 - 08-10-2015, 12:37 PM



Theme © iAndrew 2016 - Forum software by © MyBB