0

Please House how else can I iterate the 'response' because this is not working. But the connection to the dB is okay

/* AJAX SECTION COMPLETE */ $(document).ready(function() { load_comment(); function load_comment() { $.ajax({ type: "POST", url: "code.php", data: { 'comment_load_data': true }, success: function(response) { $('.comment_container').html(""); // console.log(response); $.each(response, function(key, value) { $('.comment_container').append('<div style="margin-left: 1px; width: 95%;" class="reply_box commentHeading ">\ <h6 class="username"> '+ value.user["fullname"] +' : '+ value.cmt["commented_on"] +' </h6>\ <p class="para"> '+ value.cmt["msg"] +' </p>\ <button class="reply_btn btn_warning"> Reply </button>\ <button class="view_reply_btn btn_danger"> View Replies </button>\ <div class="reply_section">\ </div>\ </div>\ '); }); } }); } });

16th Nov 2022, 12:23 PM
Code Peqatech
Code Peqatech - avatar
2 Answers
0
/*PHP SECTION */ // FETCHING COMMENTS FROM THE DB if(isset($_POST['comment_load_data'])) { $comments_query = " SELECT * FROM comments "; $comments_query_run = mysqli_query($con, $comments_query); $array_result = []; if (mysqli_num_rows($comments_query_run) > 0) { foreach($comments_query_run as $row) { $user_id = $row['user_id']; $user_query = " SELECT * FROM users WHERE id = $user_id LIMIT 1 "; $user_query_run = mysqli_query($con, $user_query ); $user_result = mysqli_fetch_array($user_query_run); array_push($array_result, ['user' => $user_result, 'cmt'=>$row]); } header('Content-type: application/json'); echo json_encode($array_result); } else { echo "Give a Comment"; } }
16th Nov 2022, 12:26 PM
Code Peqatech
Code Peqatech - avatar
0
This is the Error I'm getting: Uncaught TypeError: Cannot use 'in' operator to search for 'length' in arrays.
16th Nov 2022, 12:34 PM
Code Peqatech
Code Peqatech - avatar