V
V
Vyacheslav Alekseevich2018-03-06 12:16:17
PHP
Vyacheslav Alekseevich, 2018-03-06 12:16:17

How to create a correct php script to create .json?

Good afternoon!
Friends, help write a script to create an array of data from the database.
There is a script that creates a file with a .json extension

function get_data() {
  ......
  $connection = mysql_connect($host, $user, $pass);
  $dbconnect = mysql_select_db($db, $connection);
  if(!$dbconnect) {
      die("Unable to connect to the specified database!");

  } else {
    $query = "SELECT * FROM Group_info";
    $result = mysql_query($query, $connection);
    $group_info_data = array();

    while ($row = mysql_fetch_array($result)) {
      $group_info_data[] = array(
         
              'Title'		=> $row["Title"],
        'Text'		=> $row["Text"],
        'Date'		=> $row["Date"],
        'Images' 	=> $row["Images"]
      );
    }
    return json_encode($group_info_data);
  }
}
$file_name = 'Group_info.json';
if (file_put_contents($file_name,'{"Test":' . get_data() . '}')) {
  echo $file_name . ' is created';
} else {
  echo "ERROR";
}
?>

Output example:
5a9e5b441bcd9007858908.png
However, I want to display not just one table, but all tables associated with it, something like this:
5a9e5bfd13d86780494402.png
Database example:
5a9e5c5766116803917775.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Kuznetsov, 2018-03-06
@dima9595

So what's the problem? Create a normal request with add. tables. You are trying to get data from only one table.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question