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
- <script type="text/javascript">
-
- $(function(){
-
- $('#email').blur(function() {
- var email = $('#email').val();
-
- $.ajax({
- type: 'POST',
- url: "searchdb3.php",
- data: {email: email},
- dataType: 'JSON',
- success: function(data) {
-
- //Display value inside text boxes
- // This only works if you have one record
// Need to access the first record.
- $('#fname').val(data.firstname);
- $('#lname').val(data.lastname);
- }
- });
- });
- });
- </script>
post to searchdb3.php
- $mysqli = new mysqli($hostname_db, $username_db, $password_db, $database_db);
-
- $em = isset ($_POST['email']) ? $_POST['email'] : false;
- $em = mysql_real_escape_string($em) ;
- if($result = $mysqli->query("SELECT firstname, lastname FROM timembers WHERE email = '". $em ."' " )) :
- if($result->num_rows ==0) :
- echo "no Rows";
- else:
- while($row = $result->fetch_object()):
- echo json_encode($row);
- endwhile;
-
- endif;
- else:
- echo "bad Query";
- endif;
-