title: Why this json_encode() is not working
body: <p>Why this json encode format is not working .If I write it outside of the all  brackets.Then it works,but get only one row.Plz help</p>
  
  <pre><code>$sql=mysqli_query($database,"SELECT * FROM com  ORDER by time DESC");
  while($row=mysqli_fetch_array($sql)){
          $mid=$row['id'];
          $text=$row['text'];
  
          if($text) {
              $response=array();
  
              $response['msg']=$text;
              $response['id']=$id;
              echo json_encode($response);
          }
  }
      //$response=array();
  
      // $response['msg']=$text;
      // $response['id']=$mid;
      // echo json_encode($response);
  </code></pre>
  
  <p>Jquery for getting above results.</p>
  
  <pre><code>function com(id){
      $.post('load.php', {tocom:id},function(data) {
          var json = eval('(' + data + ')');
          if(json['msg'] != "") {
              var msg=json['msg'];
              var fro=json['id'];
              $("#msg).html(fro+msg);
          }
        });
  }
  </code></pre>