Reputation: 11
How to Convert mysql all tables to json(How to Select Multiple tables, not one);
I am trying to select multiple table of my db: then convert it from mysql to json format Please guide me!
<body>
<?php
$connect = mysqli_connect("localhost", "root", "", "martlink_db");
$sql = "SELECT * FROM users";
$result = mysqli_query($connect, $sql);
$json_array = array();
while($row = mysqli_fetch_assoc($result))
{
$json_array[] = $row;
}
echo '<pre>';
print_r(json_encode($json_array));
echo '</pre>';
//echo json_encode($json_array);
?>
</body>
Upvotes: 1
Views: 279
Reputation: 73
Check the following query
<?php
$connect = mysqli_connect("localhost", "root", "", "martlink_db");
$sql ="SELECT * FROM table1 t1,table2 t2 where condition"
$stmt = $conn->query($sql);
$jsonArr = array();
do
{
$rowset = $stmt->fetchAll(PDO::FETCH_NUM);
if ($rowset)
{
$jsonArr[] = tojson($rowset, $i);
}
}while ($stmt->nextRowset());
?>
Upvotes: 1