Answer the question
In order to leave comments, you need to log in
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";
}
?>
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question