1

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>  

1 Answer 1

1

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()); 
?>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.