Welcome Guest, Not a member yet? Register   Sign In
nested comment
#1

[eluser]rebornishard[/eluser]
database structure
Code:
[b]db_users[/b]
id_user
user_name
[b]db_posts[/b]
id_post
user_id
post_title
post_content
[b]db_comments[/b]
id_comment
post_id
user_id <-- 0 if comment come from guest / non member
comment_date
comment_author
comment_content
comment_parent <-- default 0 = not nested

model post
Code:
class Post extends CI_Model
{
function get_post($ID = FALSE)
{
  $query = $this->db->get_where('db_posts', array('id_post' => $ID));
  return $query->row_array();
}

        function get_comment($ID = FALSE)
{
  $query2 = $this->db->get_where('db_comments', array('post_id' => $ID));
  return $query2->row_array();
}

        public function get_author($ID = FALSE)
{
  $query3 = $this->db->query("SELECT db_users.id_user, db_users.user_name, db_comments.id_comment, db_comments.post_id, db_comments.user_id, db_comments.comment_date, db_comments.comment_author, db_comments.comment_content, db_comments.comment_parent, db_posts.id_post, db_posts.user_id, db_posts.post_title, db_posts.post_title, db_posts.post_content
FROM (db_users LEFT JOIN db_posts ON db_users.id_user = db_posts.user_id)
LEFT JOIN db_comments
ON db_comments.post_id=db_posts.id_post
WHERE db_comments.post_id = '$ID'
ORDER BY db_comments.comment_date DESC");
  return $query3->result_array();
}
}

controller posts
Code:
class Posts extends CI_Controller
{

function __construct()
{
  parent::__construct();
  $this->load->model('post');
}

function view($ID)
{
  $data['post'] = $this->post->get_post($ID);
  $data['comment'] = $this->post->get_comment($ID);
  $data['author'] = $this->post->get_author($ID);

  if (empty($data['post']))
  {
   show_404();
  }

  $this->load->view('view', $data);
}
}

view
Code:
&lt;?php
echo '<h2>'.$post['post_title'].'</h2>';
echo $post['post_content'].'<br />';

if (empty($comment['post_id']))
{

}
else
{

if ($comment['user_id']==0)
{
  if ($comment['comment_parent']==0)
  {
   foreach ($author as $row)
   {
    echo '<b>'.$row['comment_author'].'</b>';
    echo '<br />'.$row['comment_content'].'<br />';
   }
  }
  else //nested comment should be here
  {
   foreach ($author as $row)
   {
    echo '<b>'.$row['comment_author'].'</b>';
    echo '<br />'.$row['comment_content'].'<br />';
   }
  }
}

else
{
  if ($comment['comment_parent']==0)
  {
  foreach ($author as $row)
  {
   echo '<b>'.$row['user_name'].'</b>';
   echo '<br />'.$row['comment_content'].'<br />';
  }
  }
  else //nested comment should be here
  {
   foreach ($author as $row)
   {
   echo '<b>'.$row['user_name'].'</b>';
   echo '<br />'.$row['comment_content'].'<br />';
   }
  }
}

}

i aim for

comment 1 <--a
-reply for a <--b
--reply for b <---c
---reply for c

could anyone help me ?
thank you Smile
#2

[eluser]InsiteFX[/eluser]
So You Want Indents and Lists, Huh?
#3

[eluser]rebornishard[/eluser]
[quote author="InsiteFX" date="1340949888"]So You Want Indents and Lists, Huh?
[/quote]
not that sir, but i wanted post comment such as them
#4

[eluser]InsiteFX[/eluser]
You could use css margins and offset it in your div.
Code:
// css file - you would need to ajust them for what you want.
.comments { width: 100%; margin: 0 auto; }
.indent-1 { margin-left: 0; }
.indent-2 { margin-left: 20px; }
.indent-3 { margin-left: 40px; }

.indent-1,
.indent-2,
.indent-3 { width: 100%; }

// html divisions
<div class="comments">
    <div class="indent-1">your comments</div>
    <div class="indent-2">your comments</div>
    <div class="indent-3">your comments</div>
</div>
You just need to indent them. You could use a for loop and increment the indent variable.
#5

[eluser]rebornishard[/eluser]
[quote author="InsiteFX" date="1340957799"]You could use css margins and offset it in your div.
Code:
// css file - you would need to ajust them for what you want.
.comments { width: 100%; margin: 0 auto; }
.indent-1 { margin-left: 0; }
.indent-2 { margin-left: 20px; }
.indent-3 { margin-left: 40px; }

.indent-1,
.indent-2,
.indent-3 { width: 100%; }

// html divisions
<div class="comments">
    <div class="indent-1">your comments</div>
    <div class="indent-2">your comments</div>
    <div class="indent-3">your comments</div>
</div>
You just need to indent them. You could use a for loop and increment the indent variable.
[/quote]
this is what i will do after that nested work,
but that comment itself still not nested

thank you sir Smile




Theme © iAndrew 2016 - Forum software by © MyBB