-1

php code:

$query = mysqli_query($con,"INSERT INTO tlb_comments(user_id,comments) values ('$vw_id','$name')");
$comments = mysqli_query($con,"SELECT * FROM tlb_comments");
$avatar   = mysqli_query($con,"SELECT * FROM tlb_avatar WHERE `vw_id`='".$vw_id."'");
$avatar_select  =  mysqli_fetch_all($avatar);
$comment_select =  mysqli_fetch_all($comments);
array_push($avatar_select,$comment_select);
echo json_encode($avatar_select);

Jquery Ajax:

$(".comment").click(function() {
    var id = $(this).data("id");
    var name = $("#username_" + id).val();
    if (name == '') {
        alert("Please Fill All Fields");
    } else {

        $.ajax({
            type: "POST",
            url: "comments",
            data: {
                username: name
            },
            success: function(html) {

                $("#cmt_output").html(html);
                console.log(html);
            }
        });
    }
});

Json Array:

[
   [
      "11",
      "6",
      "1509947417_User_Avatar_2.png"
   ],
   [
      [
         "113",
         "0",
         "6",
         "all of us",
         "0"
      ],
      [
         "114",
         "0",
         "6",
         "all of us",
         "0"
      ],
      [
         "115",
         "0",
         "6",
         "welcome....",
         "0"
      ]
   ]
]
4b0
  • 21,981
  • 30
  • 95
  • 142
John Bright
  • 84
  • 1
  • 10

1 Answers1

0

I think you have to return the asssociative array from php so you can easily read the json array with key of each array element...