さて、私がやろうとしているのは、Jsonデコードされた配列を繰り返し、ID(キー)を検索し、そのデータを編集用のフォームに投稿し、エンコードして保存することです。これはとても簡単な作業のようですが、私は使用していません。データベースまたはJavaまたはJavaスクリプトJson、PHP、およびHTMLのみを使用してこれを行う必要があります私のメインコード(コントローラー)ファイルは次のとおりです
<?php
$file_name = 'engagements.json'; // Serialized speaking engagments
/**
* Controller for Speaking Engagements
*/
if (!isset($_REQUEST['act']) || !$action = $_REQUEST['act']){
$action = 'list';
} //End If
switch ($action) {
case 'list': // List
$json_data = file_get_contents($file_name);
if (!$engagements = json_decode($json_data, true)) { // Convert serialized data to array
$engagements = array();
} //End If
include 'engagements_list.phtml';
break;
case 'view': // View
$json_data = file_get_contents($file_name);
$temp_array = json_decode($json_data);
foreach($temp_array as $key=>$id){
if($id->ID == 2){
echo "got it \n";
echo "ID: $id->ID \n";
echo "Title: $id->Title \n";
echo "Description: $id->Description \n";
}// End If
}
break;
case 'add': // Add
$temp_array = array();
$file = file_get_contents($file_name);
$json_data = json_decode($file);
$high_value = count($json_data);
$high_value++;
$temp_array['ID'] = $high_value;
$temp_array['Title'] = $_POST['Title'];
$temp_array['Description'] = $_POST['Description'];
$json_data[] = $temp_array;
file_put_contents($file_name, json_encode($json_data));
include 'engagements_add.phtml';
break;
case 'edit': // Edit
$file = file_get_contents($file_name);
$json_data = json_decode($file, true);
// what comes next here
include 'engagements_edit.phtml';
break;
case 'delete': // Delete
break;
default:
throw(new Exception('Invalid action given'));
break;
}//End Switch
exit;
<!-- Edit View -->
<form action="engagements.php?act=edit?ID=<?php $_GET['ID']?>" method="get">
<table>
<tr><td><input type="hidden" name="ID"></td></tr>
<tr><td><input type="text" style="width:500px;" name="Title"></td></tr>
<tr><td><textarea cols="40" rows="2" style="width: 500px; height:250px;" name="Description"></textarea></td></tr>
<tr><td><input type="submit" name="Submit" value="Submit"/></td></tr>
</table>
</form>
私が答えをどこでも検索したが、これを適切に行う方法を説明するリソースを見つけることができるのを助けてください