How would I access Multiple records inside JSON

How would I access Multiple records inside JSON

How would I access Multiple records inside JSON
This sample only works if i have one record.

Thanks to POPNoodles for helping me so far


  1.     <script type="text/javascript">
  2.    
  3.         $(function(){
  4.            
  5.             $('#email').blur(function() {
  6.                   var email = $('#email').val();
  7.                
  8.                 $.ajax({
  9.                   type: 'POST',
  10.                   url: "searchdb3.php",
  11.                   data: {email: email},
  12.                   dataType: 'JSON',
  13.                   success: function(data) {
  14.                                      
  15.                   //Display value inside text boxes   
  16.                   // This only works if you have one record
                      // Need to access the first record.
  17.                   $('#fname').val(data.firstname);
  18.                   $('#lname').val(data.lastname);
  19.                   }
  20.                 });
  21.             });
  22.         });
  23.     </script>

post to searchdb3.php
  1. $mysqli = new mysqli($hostname_db, $username_db, $password_db, $database_db);
  2.  
  3. $em =  isset ($_POST['email']) ? $_POST['email'] : false;
  4. $em =  mysql_real_escape_string($em) ;
  5. if($result = $mysqli->query("SELECT firstname, lastname FROM timembers WHERE email = '". $em ."' " )) :
  6.     if($result->num_rows ==0) :
  7.         echo "no Rows";
  8.     else:
  9.     while($row = $result->fetch_object()):   
  10.             echo json_encode($row);
  11.     endwhile;
  12.        
  13.     endif;
  14. else:
  15.     echo "bad Query";
  16. endif;
  17.