I apologize for my bad English, I hope I can explain myself better.
- Json file: through this code the call is made to view the contents of the file:
<? php
$ login = 'XL8T7924H9G9U1M99GTSVV9BHC2KYRFL';
$ password = '';
$ url = 'https://www.website.com/api/products?&output_format=JSON&display=full';
$ ch = curl_init ();
curl_setopt ($ ch, CURLOPT_URL, $ url);
curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt ($ ch, CURLOPT_USERPWD, "$ login: $ password");
$ result = curl_exec ($ ch);
curl_close ($ ch);
$ json = json_decode ($ result, true);
/ echo ($ result);
?>
- results are shown with datatable this code
<form action = "" method = "post">
<table id = "example" class = "table table-striped table-bordered zero-configuration">
<thead>
<tr>
<th class = "th-sm"> # </th>
<th class = "th-sm"> Name </th>
<th class = "th-sm"> Description </th>
<th class = "th-sm"> Short Description </th>
<th class = "th-sm"> Image </th>
<th class = "th-sm"> Activate </th>
</tr>
</thead>
<tbody>
<div class = "form-group" style = "text-align: -webkit-center;">
<div class = "form-check form-check-inline">
<? php
foreach ($ json ['products'] as $ data)
{
echo "<tr>";
echo "<td>". $ data ['id']. "</td>";
echo "<td>". $ data ['name']. "</td>";
echo "<td>". $ data ['description']. "</td>";
echo "<td>". $ data ['description_short']. "</td>";
echo "<td>". '<img src = "http://www.website.com/'.$data [" id_default_image "] .'- home_default /'.$ data [" link_rewrite "].'. jpg" class = "img-thumbnail "width =" 120 "height =" auto "/> ';
echo "<td> <input type = 'checkbox' name = 'checkbox' value = '1'> </td>";
echo "</tr>";
}?>
</tbody>
</table>
<input type = "submit" name = "submitp" id = "submitp" value = "submit">
</form>
- through a checkbox and submit I can save the information on a txt file this is the code
<? php
if (isset ($ _ POST ['submitp'])) {
$ id = "product id:". $ _ POST ['id']. "";
$ name = "product name:". $ _ POST ['name']. "";
$ description = "product description:". $ _ POST ['description']. "";
$ description_short = "short product description:". $ _ POST ['description_short']. "";
$ image = "product image:". $ _ POST ['image']. "";
$ file = fopen ("file.txt", "w +");
fwrite ($ file, $ id);
fwrite ($ file, $ name);
fwrite ($ file, $ description);
fwrite ($ file, $ short_description);
fwrite ($ file, $ image);
fclose ($ file);
}
?>
I know I'm wrong but I can't figure out how to save the entire selected row.
what you want to achieve: saving the selected row with its id, name, description and short description through the checkbox
errors: none
what it saves: only the contents of the checkbox
I hope I have explained myself well and thank you for your help
My Answer:
// Read JSON file
$json = file_get_contents('data.json');
// Decode JSON file
$data = json_decode($json, true);
// Display data
foreach ($data as $row) {
echo '' . $row['name'] . '
Rate this post
4 of 5 based on 7884 votesComments