試合データ入力
12:00:000
$date,
‘home_team’ => $_POST[‘home_team’],
‘away_team’ => $_POST[‘away_team’],
// その他のデータ
];
if ($_SERVER[‘REQUEST_METHOD’] === ‘POST’) {
// ディレクトリ作成&保存処理
$date = $_POST[‘date’];
$year = date(‘Y’, strtotime($date));
$dataDir = “data/$year”;
}
// 保存するデータのディレクトリパスを指定
$dataDir = ‘data/’ . date(‘Y’) . ‘/’ . date(‘md’); // 年/月日(例:1222)
$fileName = uniqid() . ‘.json’; // ユニークIDを生成してファイル名に
// ディレクトリが存在しない場合は作成
if (!file_exists($dataDir)) {
mkdir($dataDir, 0777, true); // ディレクトリ作成
}
// 保存するデータの準備
// 現在の日付を取得
$date = date(‘Y-m-d H:i:s’);
// フォームから送信されたデータを取得
$home_team = isset($_POST[‘home_team’]) ? $_POST[‘home_team’] : ”;
$away_team = isset($_POST[‘away_team’]) ? $_POST[‘away_team’] : ”;
// 選手名、ゴール数、シュート数を取得
$home_players = isset($_POST[‘home_players’]) ? $_POST[‘home_players’] : [];
$home_goals = isset($_POST[‘home_goals’]) ? $_POST[‘home_goals’] : [];
$home_shots = isset($_POST[‘home_shots’]) ? $_POST[‘home_shots’] : [];
$away_players = isset($_POST[‘away_players’]) ? $_POST[‘away_players’] : [];
$away_goals = isset($_POST[‘away_goals’]) ? $_POST[‘away_goals’] : [];
$away_shots = isset($_POST[‘away_shots’]) ? $_POST[‘away_shots’] : [];
// 選手情報を組み合わせる
$home_players_data = array_map(function($player, $goal, $shot) {
return [‘player’ => $player, ‘goal’ => $goal, ‘shot’ => $shot];
}, $home_players, $home_goals, $home_shots);
$away_players_data = array_map(function($player, $goal, $shot) {
return [‘player’ => $player, ‘goal’ => $goal, ‘shot’ => $shot];
}, $away_players, $away_goals, $away_shots);
// 保存するデータの準備
$data = [
‘date’ => $date,
‘home_team’ => $home_team,
‘away_team’ => $away_team,
‘home_players’ => $home_players_data,
‘away_players’ => $away_players_data,
];
// $_POST データがある場合のみ取得、それ以外は空の配列
$home_players = isset($_POST[‘home_players’]) ? $_POST[‘home_players’] : [];
$home_goals = isset($_POST[‘home_goals’]) ? $_POST[‘home_goals’] : [];
$home_shots = isset($_POST[‘home_shots’]) ? $_POST[‘home_shots’] : [];
$away_players = isset($_POST[‘away_players’]) ? $_POST[‘away_players’] : [];
$away_goals = isset($_POST[‘away_goals’]) ? $_POST[‘away_goals’] : [];
$away_shots = isset($_POST[‘away_shots’]) ? $_POST[‘away_shots’] : [];
// 選手情報(選手名、得点、シュート数)を組み合わせ
$data = [
‘date’ => date(‘Y-m-d H:i:s’),
‘home_team’ => $_POST[‘home_team’],
‘away_team’ => $_POST[‘away_team’],
‘home_players’ => array_map(function($player, $goal, $shot) {
return [‘player’ => $player, ‘goal’ => $goal, ‘shot’ => $shot];
}, $home_players, $home_goals, $home_shots),
‘away_players’ => array_map(function($player, $goal, $shot) {
return [‘player’ => $player, ‘goal’ => $goal, ‘shot’ => $shot];
}, $away_players, $away_goals, $away_shots),
];
// array_mapで各選手情報(選手名、得点、シュート数)を組み合わせる
$data = [
‘home_players’ => array_map(function($player, $goal, $shot) {
return [‘player’ => $player, ‘goal’ => $goal, ‘shot’ => $shot];
}, $home_players, $home_goals, $home_shots),
‘away_players’ => array_map(function($player, $goal, $shot) {
return [‘player’ => $player, ‘goal’ => $goal, ‘shot’ => $shot];
}, $away_players, $away_goals, $away_shots),
];
?>
お問い合わせ・サンプル依頼はこちら