Creating a form to update JSON Data with MySQL
Tag : php , By : snapshooter
Date : March 29 2020, 07:55 AM
seems to work fine This is the output I need: , Try this: <?php
$minimum_tracks=1;
$maximum_tracks=10;
$tracks=isset($_GET['tracks'])?$_GET['tracks']:0;
if (is_numeric($tracks) && $tracks>=$minimum_tracks && $tracks<=$maximum_tracks) {
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$_POST['cityartwork']="Default Set from PHP";
$_POST['tracks']=array();
$_POST['artwork']='http://www.ggcc.tv/ArmyoftheLord/Army%20of%20the%20Lord.png';
if ($_FILES['artwork']['size']!=0) {
move_uploaded_file($_FILES['artwork']['tmp_name'],"artworks/".$_FILES['artwork']['name']);
$_POST['artwork']=$_SERVER['HTTP_HOST']."/artworks/".$_FILES['artwork']['name'];
}
for ($i=0;$i<$tracks;$i++) {
$filename="tracks/".$_FILES['tracks']['name'][$i];
$_POST['tracks'][$i]=array(
"name"=>$_POST['track_names'][$i],
"url"=>$_SERVER['HTTP_HOST']."/".$filename
);
move_uploaded_file($_FILES['tracks']['tmp_name'][$i],$filename);
}
unset($_POST['track_names']);
echo json_encode($_POST);
exit;
} else {
?><!DOCTYPE html>
<html>
<head>
<title>New Album</title>
</head>
<body>
<form method="post" action="" enctype="multipart/form-data">
Album Name: <input type="text" name="album"><br>
Artwork: <input type="file" name="artwork"><br>
Church: <select name="church"><option value="New York NY">New York NY</option><option value="Los Angeles CA">Los Angeles CA</option></select><br>
Description: <br><textarea name="des"></textarea><br>
Release Date: <input type="date" name="release_date"><br>
Tracks: <br><br><?php
for ($i=1;$i<=$tracks;$i++) {
echo 'Track '.$i.'<br><input type="text" name="track_names[]"><input type="file" name="tracks[]"><br><br>';
}
?>
<input type="submit">
</form>
<?php
exit;
}
} else {
?>
<!DOCTYPE html>
<html>
<head>
<title>New Album</title>
</head>
<body>
How many tracks are in this album?
<form action="" method="get">
<select name="tracks">
<?php
for ($i=1;$i<$maximum_tracks;$i++) {
echo '<option value='.$i.'>'.$i.'</option>';
}
?>
</select><br>
<input type="submit">
</form>
</body>
</html>
<?php
}
?>
|
Creating JSON that contains both arrays and objects from a mySQL data source
Date : March 29 2020, 07:55 AM
I hope this helps you . I am trying to create a JSON representation of data stored in mySQL. , Edited to give the desired output $data = ['sessionToken' => '',
'roleName' => '',
'data' => [['methodTypes' => [''], 'objects' => ['']]]
];
{"sessionToken":"","roleName":"","data":[{"methodTypes":[""],"objects":[""]}]}
echo json_encode(['name' => 'value']);
{"name":"value"}
echo json_encode(['value']);
["value"]
|
MySQL, PHP, jSON append data from MySQL into an array in PHP and converting in jSON file
Tag : php , By : Sebastián Ucedo
Date : March 29 2020, 07:55 AM
wish of those help I have a little problem to code in PHP how to obtain this result with data provided from MySQL , Creating an array is as simple as: $profiles = array();
// Add an item. Array is created if $x didn't contain an array already.
$profiles[] = 'foo';
$profile = null;
$profile->UserName = $UserName;
$profile->PictureID = $PictureID;
// Etc
// Add profile object to array.
$profiles[] := $profile;
$result = null;
$result->profiles = $profiles;
echo json_encode($result);
$profile = new StdClass();
|
parsing json like data without creating a json file python
Tag : python , By : Chris Woods
Date : March 29 2020, 07:55 AM
this one helps. pd.read_json takes a file path or a string buffer, so you can pass the json string directly to it.
|
Creating a JSON file from JSON response data in Python
Tag : python , By : Tom Berthon
Date : March 29 2020, 07:55 AM
Does that help I want to take the json response data from a REST request and create an actual json file. I tried something like this, but it did not work. Essentially, it just prints the headers. Any suggestions? , use the json module my_data = json.loads(r.json())
# my_data is a dict mapping the JSON
with open(path, 'w') as f:
json.dump(my_data, f)
json.dump(my_data, f, indent=2)
|