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

[eluser]swgj19[/eluser]
I solved my problem, but somehow created another one.

On my blog, where the comments are displayed, I was using the same function to display user's corresponding post_id comments and user's corresponding comments by id in the admin panel.

So I had to write a new function for the back-end.

However, the main problem was I had to change this

Code:
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;
}

to

Code:
public function get_comments($id)
{
  
  $data = array();

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

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

  if ($query->num_rows() > 0)
  {
   $data = $query->row_array();
  }

  $query->free_result();  

  return $data;
}

Instead of using result_array(), I needed to use row_away.
I will have to look in the ci_manual to answer why.

Now the other problem that was created, is that in the admin panel, the comments are displayed in a table with id, name, email, body, post_id, status, actions.

Now when a comment is inserted on the blog home page, the comment is displayed and stored in the db.
However, when I update a comment in the admin panel (changing status enum from active to inactive or any change at all) the post_id will dissappear and default to 0, which causes the comment on the home blog page to dissappear. The reason why, is because in the function that displays the comments, it is by post_id. So somehow in one of my function I need to pass the $post_id, but I have messed with this for 4 hours and do not want to break my code.

Any suggestioins. Thanks


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