0

I have a script that reads all the rows in my table in php and shows the results in json_encode. When I want to list all the rows in a list they don't rest display. How can I display all my records. My table has 4 fields id,Name,Surname and Age. And I want the link to have the id so when a user clicks they will view the one record.

PHP

<?php
    require_once("database.php");
    $mydb = new MySQLDatabase();

    $sql = $mydb->query("Select * from tblprofile");
    $rows = array(); 
    $r = $mydb->fetch_array($sql);
    $rows[] = $r;

    echo json_encode($rows);
?>

HTML

<div data-role="page" id="listofusers" data-theme="a">
<div data-role="header" data-theme="a" data-position="fixed">
<h1>Test</h1>
</div>
 <div data-role="content" data-theme="a" id="listofusers_content">  
    <ul data-role="listview" data-theme="a">
    <script type="text/javascript">
   $(document).ready(function(){
      $.getJSON('http://localhost/v_warehouse_1/inc/getprofiles.php', function(data) {
       $.each(data, function(key, val) {
        $('ul').append('<li id="' + key + '">' + val.Tip + '</li>');
         });
         });
         });
</script>
</ul>
  </div>
   <div data-role="footer" data-theme="a" data-position="fixed">
    <h4>Test</h4>
  </div>
</div>

1 Answers1

0

You could use fetch_all method (http://php.net/manual/en/mysqli-result.fetch-all.php):

require_once("database.php");
$mydb = new MySQLDatabase();

if ($result = $mydb->query("SELECT * FROM tblprofile")) {
  $rows = $result->fetch_all(MYSQLI_ASSOC); // eventually MYSQLI_NUM
  echo json_encode($rows);
}
Reversal
  • 622
  • 5
  • 19