johansson johansson - 1 year ago 63
PHP Question

View data with json php mysqli in tag table

I have table users :

  • id

  • login

  • password

and i have this code to display data :

page : config.php :

$rep = $db->query("SELECT * FROM users");
$array_user[] = array();
while($data = $rep->fetch()){
$array_user = $data;
echo json_encode($array_user);

page : list.php :

<div id="tab"></div>


var loadData = function(){
var users = JSON.parse(data);

for(var i in users){
$("#tab").append(users[i].login + "<br>");


but i want to display id and login in tag table
for example :

<table id="tab">

<td>(display data with json : id)</td>
<td>(display data with json : login )</td>

Answer Source

For one thing, you need to reference the td tags, otherwise you're just appending to the table itself. For example:

for(var i in users){
    var data = '<tr><td>' + users[i].id + '</td></tr><tr><td>' + users[i].login + '</td></tr>';
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download