I have an object that I get from a "SHOW tables" query. Unfortunately, I get an array inside an object has a name that changes based on what user is logged in (eg. data[1].Tables_in_kazura). How can I either access what user is logged in or even better rename the result from PHP, from Tables_in_xxx to whatever I want?
$.getJSON("php/loadCategories.php", function(data) {
for (let i = 0; i < data.length; i++) {
console.log(data[i]);
}
});
This is my PHP
$sql = "SHOW tables";
$rows = $db->query($sql);
$length = $rows->num_rows;
$result = array();
for ($i = 0; $i < $length; $i++) {
$row = $rows->fetch_assoc();
array_push($result, $row);
}
echo json_encode($result);
The echo $result gives me:
Object { Tables_in_kazura: "drinks" }
Object { Tables_in_kazura: "food" }
and what ever else the user (user here is kazura) has in his tables.
Since it is based on username, Tables_in_USERNAME will vary and I don't know how I can access the data inside it.
The optimal solution would be that echo json_encode($result);
returns Object { categoryname: "drinks" }
and so on no matter what user is logged in