<?php if (isset($GLOBALS['comments']) && is_array($comments)) { ///This just checks to see if the global variable comments is available. If it is then it will do the code below. If there is a problem an error message wont appear but either will teh comments. ?> <?php foreach ($comments as $key => $comment) { foreach ($comment as $key2 => $comment2) { $user = Subscribers::getSubscriber($comment2->userId); ?> <li class="comment-holder" id="_<?php echo $comment2->comment_id; ?> "> <div class="user-img"> <img src='<?php echo $user[2]; ?> ' class="user-img-pic"/> </div> <div class="comment-body"> <h3 class="username-field"> <?php echo $user[1]; ?> </h3>
<?php if (isset($_POST['task']) && $_POST['task'] == 'comment_insert') { $userId = $_POST['userId']; $comment = str_replace("\n", "<br>", $_POST['comment']); $std = new stdClass(); $std->user = null; $std->comment = null; $std->error = false; require_once '../sql/models/comments.php'; if (class_exists('Comments') && class_exists('Subscribers')) { $userInfo = Subscribers::getSubscriber($userId); if ($userInfo == null) { //Cause some problems $std->error = true; } $commentInfo = Comments::insert($comment, $userId); if ($commentInfo == null) { //Cause some problems $std->error = true; } $std->user = $userInfo; $std->comment = $commentInfo; } echo json_encode($std); } else { }