Ajax and PHP with a while loop issue
<p>I have a ajax that needs to return some values, but if I use a <code>while()</code> to get all the result from my db, the return is "nothing". Where am I making mistake?</p>

<p>My Ajax script is posted below:</p>

<pre><code>&lt;script type="text/javascript" charset="utf-8"&gt;
  function addmsg(type, msg) {
    var obj = jQuery.parseJSON(msg);
    // Your count variable
    var count = obj.count;
    // Your not variable
    var not = obj.not;
    $('#msg_count').html(count);
    $('#notification').html(not);

  }

  function waitForMsg() {
    $.ajax({
      type: "GET",
      url: "notification/select.php",
      cache: false,
      timeout: 50000,

      success: function(data) {
        addmsg("new", data);
        setTimeout(
          waitForMsg,
          1000
        );
      },
      error: function(XMLHttpRequest, textStatus, errorThrown) {
        addmsg("error", textStatus + " (" + errorThrown + ")");
        setTimeout(
          waitForMsg,
          15000);
      }
    });
  };

  $(document).ready(function() {

    waitForMsg();

  });
&lt;/script&gt;
</code></pre>

<p>My php script is posted below:</p>

<pre><code> $result = mysqli_query($con, "SELECT * from notification where tousername='$tousername' and isread = 0");

 while ($row = mysqli_fetch_array($result)) {
     $count = $result - &gt; num_rows;
     $not = $row['notification_msg'];
     $res = [];
     $res['count'] = $count;
     $res['not'] = $not;
 }
 echo json_encode($res);
</code></pre>