title: "$.get" for retrieving information
body: <p>I'm trying to get a simple javascript popup script going anytime the database is updated in real-time. I'm not sure as to what to do next, because I'm still a newbie with jQuery and ajax, but the following code is what I have right now:</p>
  
  <p>PHP MySQL query page:</p>
  
  <pre><code>&lt;?php
  
  $con = mysqli_connect('localhost','root','root','mydb');
  if (!$con) {
      die('Could not connect: ' . mysqli_error($con));
  }
  
  mysqli_select_db($con,"mydb");
  $sql = "SELECT * FROM incoming_calls";
  $result = mysqli_query($con,$sql);
  
  while($row = mysqli_fetch_array($result)) {
      //$callArray = array('phonenumber' =&gt; $row['phone_number'], 'id' =&gt; $row['phone_login_id']);
      if(!empty($row)) {
      $number = $row['phone_number'];
      }
  }
  
  $sql="SELECT Username, Password FROM tblUsers WHERE PhoneHome='$number' OR PhoneCell='$number' OR PhoneWork='$number'";
  $result = mysqli_query($con,$sql);
  
  while($row = mysqli_fetch_array($result)) {
      $userArray = array("username" =&gt; $row['Username'], "password" =&gt; $row['Password']);
      //echo json_encode($userArray);
  }
      echo json_encode($userArray);
  
  mysqli_close($con);
  ?&gt;
  </code></pre>
  
  <p>HTML page:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt; 
  &lt;html lang="en-US"&gt; 
  &lt;head&gt; 
  &lt;meta charset="utf-8"&gt; 
  &lt;title&gt;Phone calls&lt;/title&gt;
  &lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;script language="javascript" type="text/javascript"&gt;
  function getCall(){
    $.get("phonecall.php", function(data){
      var loginInfo = jQuery.parseJSON(data);
      var user = loginInfo.username;
      var pass = loginInfo.password;
      $('#username').html(user);
      $('#password').html(pass);
    });
  
  /*$.getJSON("phonecall.php", function(data){
      for (var i=0, len=data.length; i &lt; len; i++) {
          $('#username').html(data);
    }
   });*/
  }
  setInterval(getCall,5000);
  &lt;/script&gt;
  
  &lt;div id="username"&gt;&lt;/div&gt;
  &lt;div id="password"&gt;&lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>One of the problems I am having is that when there are 2 or more users with the same phone number for say like a house phone, depending on where the json_encode is, will either return the last entry in the table, or return nothing at all. If the json_encode is in the while loop, I can check the console, it says the information is being retrieved, but something must not be right with my "$.get" syntax to allow more than one entry to be displayed. Any ideas?</p>