Welcome Guest, Not a member yet? Register   Sign In
undefined index
#2

[eluser]swgj19[/eluser]
Model:
Code:
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Comment_model extends CI_Model {

// --------------------------------------------------------------------

/**
  * __construct()
  *
  * Constructor PHP 5+ NOTE: Not needed if not setting values!
  *
  * @access public
  * @return void
  */
public function __construct()
{
  parent::__construct();
}

// --------------------------------------------------------------------

/**
  * get_comments()
  *
  * Description:
  *
  * @access public
  * @param string
  * @return void
  */
public function get_comments($post_id = null)
{
  
  $data = array();

  $this->db->where('post_id', $post_id);

  $query = $this->db->get('comments');

  if ($query->num_rows() > 0)
  {
   foreach ($query->result_array() as $row)
   {
    $data[] = $row;
   }
  }

  $query->free_result();  

  return $data;
}

// --------------------------------------------------------------------

/**
  * get_all_comments()
  *
  * Description:
  *
  * @access public
  * @return void
  */
public function get_all_comments()
{
  $data = array();

  $query = $this->db->get('comments');

  if ($query->num_rows() > 0)
  {
   foreach ($query->result_array() as $row)
   {
    $data[] = $row;
   }
  }

  $query->free_result();  

  return $data;
}

// --------------------------------------------------------------------

/**
  * get_all_comments_post()
  *
  * Description:
  *
  * @access public
  * @param string
  * @return void
  */
public function get_all_comments_post($post_id)
{
  $data = array();

  $this->db->where("post_id", $post_id);
  $this->db->where('status', 'active');

  $query = $this->db->get('comments');

  if ($query->num_rows() > 0)
  {
   foreach ($query->result_array() as $row)
   {
    $data[] = $row;
   }
  }

  $query->free_result();  

  return $data;
}

// --------------------------------------------------------------------

/**
  * add_comment()
  *
  * Description:
  *
  * @access public
  * @return void
  */
public function add_comment()
{
  $now = date("Y-m-d H:i:s");

  $data = array(
   'name'  => $this->input->post('name'),
   'email'  => $this->input->post('email'),
   'body'  => strip_tags(substr($this->input->post('body'), 0, 255)),
   'post_id' => $this->input->post('post_id'),
   'pub_date' => $now,
  
  );

  $this->db->insert('comments', $data);  
}

// --------------------------------------------------------------------

/**
  * update_comment()
  *
  * Description:
  *
  * @access public
  * @return void
  */
public function update_comment()
{
  $data = array(
   'name'  => $this->input->post('name'),
   'email'  => $this->input->post('email'),
   'body'  => $this->input->post('body'),
   'post_id' => $this->input->post('post_id'),
   'pub_date' => $this->input->post('pub_date'),
   'status' => $this->input->post('status'),
  );

  $this->db->where('id', $this->input->post('id'));
  $this->db->update('comments', $data);
  
  //return $data;
}

// --------------------------------------------------------------------

/**
  * delete_comment()
  *
  * Description:
  *
  * @access public
  * @param string
  * @return void
  */
public function delete_comment($id)
{
  $this->db->where('id', $id);
  $this->db->delete('comments');

  // this will delete - remark out or delete the top 2 lines
  $this->db->delete('comments', array('id' => $id));
}

}


// ------------------------------------------------------------------------
/* End of file category_model.php */
/* Location: ./application/models/category_model.php */


Messages In This Thread
undefined index - by El Forum - 11-27-2012, 01:53 AM
undefined index - by El Forum - 11-27-2012, 01:54 AM
undefined index - by El Forum - 11-27-2012, 04:12 AM
undefined index - by El Forum - 11-27-2012, 04:44 AM
undefined index - by El Forum - 11-27-2012, 05:06 AM
undefined index - by El Forum - 11-27-2012, 05:07 AM
undefined index - by El Forum - 11-27-2012, 05:35 AM
undefined index - by El Forum - 11-27-2012, 05:44 AM
undefined index - by El Forum - 11-27-2012, 05:56 AM
undefined index - by El Forum - 11-27-2012, 06:07 AM
undefined index - by El Forum - 11-27-2012, 06:21 AM
undefined index - by El Forum - 11-27-2012, 06:23 AM
undefined index - by El Forum - 11-27-2012, 07:49 AM
undefined index - by El Forum - 11-27-2012, 09:30 AM
undefined index - by El Forum - 11-27-2012, 09:39 AM
undefined index - by El Forum - 11-27-2012, 10:08 AM
undefined index - by El Forum - 11-27-2012, 01:18 PM



Theme © iAndrew 2016 - Forum software by © MyBB