サイトを検索しましたが、答えが見つからないか、クエリの設定方法との関連性がわかりません。これは、投稿データを処理して db に渡すファイルです。テーブルに巻きつけるようなフォルムをしています。テーブル内のセルは、配列によって設定されます。このページを離れるときに、テーブル セルの値をデータベースの新しいテーブルに書き込む必要があります。テーブルの各行は、db の個別の行を表します。
これが私のすべての投稿データの元となる私のフォームです。
<form action="post_movement.php?class_id=<?php echo $class_id; ?>&pagenum=<?php echo $pagenum; ?>" method="post">
<table border=1 width=800px>
<tr>
<th width=300px>Client</th>
<th width=50px>Order</th>
<th width=200px>Movements</th>
<th>Sets/Reps/Seconds</th>
<th width=150px>Rest</th>
<th>X Completed</th>
</tr>
<?php
// Get workout class and output in table format -------------------------------------------------
if(empty($workout_class) === false)
{
foreach($workout_class as $wc){
if ($wc['pagenum'] !== $pagenum) continue 1;
echo '<tr>
<td><input type="hidden" name="first_name[]" value="'.($wc['first_name']).'">'. ($wc['first_name']).'
<span><input type="hidden" name="nickname[]" value="'.($wc['nickname']).'">('. ($wc['nickname']).')</span>
<span><input type="hidden" name="last_name[]" value="'.($wc['last_name']).'">'. ($wc['last_name']).'</span>
</td>
<td><input type="hidden" name="order[]" value="'.($wc['order']).'">'. ($wc['order']). '</td>
<td>
<select name="movement[]" width=200>
<option>'. ($wc['mv_00']). '</option>
<option>'. ($wc['mv_01']). '</option>
<option>'. ($wc['mv_02']). '</option>
<option>'. ($wc['mv_03']). '</option>
<option>'. ($wc['mv_04']). '</option>
</select></td>
<td><input type="hidden" name="rep_set_sec[]" value="'.($wc['rep_set_sec']).'">'. ($wc['rep_set_sec']). '</td>
<td><input type="hidden" name="rest[]" value="'.($wc['rest']).'">'. ($wc['rest']). '</td>
<td>00</td>
</tr>';
} // foreach($data_array
//print_r($data_array);
} // if(!empty
?>
<! End Table ---------------------------------------------------------------------------------->
</table>
<input type="submit" value="Complete Movement">
</form>
これは、フォームからの投稿データを処理してクエリに送信する私のphpです。
if (empty($_POST)=== false){
$movement_data = array('user_id', 'class_id', 'class_name', 'first_name', 'last_name', 'nickname', 'order', 'movement', 'rep_set_sec', 'rest', 'date');
foreach($movement_data as $key => $value){
$movement_data = array(
'user_id' => $session_user_id,
'class_id' => $_GET['class_id'],
'class_name' => $class_name,
'first_name' => $_POST['first_name'],
'last_name' => $_POST['last_name'],
'nickname' => $_POST['nickname'],
'order' => $_POST['order'],
'movement' => $_POST['movement'],
'rep_set_sec' => $_POST['rep_set_sec'],
'rest' => $_POST['rest'],
'date' => $today
);
}
completed_movement($movement_data);
//header('Location: new_client.php');
//exit ();
}
これは、POST データを db に挿入するクエリです。
function completed_movement($movement_data){
array_walk($movement_data, 'array_sanitize');
$fields = '`' . implode('`, `', array_keys($movement_data)) . '`';
$data = '\'' . implode('\', \'', $movement_data) . '\'';
$query = mysql_query ("INSERT INTO `completed_movements` ($fields) VALUES ($data)");
}
HTML フォーム ページには 2 つのテーブル行のデータがあり、次のようになります。
Colby (Big Cheese) Dodson | 1A | Key Movement | Sets/Reps/Seconds | Rest|
-------------------------------------------------------------------------
Mike (Big Mac) Mckenzie | 1A | Key Movement | Sets/Reps/Seconds | Rest|
var_dump ($_POST) がこれを生成します。そこにその価値があることがわかりますが、それが想定どおりに見えるかどうかはわかりません。
array(7) {
["first_name"]=> array(2) {
[0]=> string(5) "Colby"
[1]=> string(4) "Mike" }
["nickname"]=> array(2) {
[0]=> string(10) "Big Cheese"
[1]=> string(7) "Big Mac" }
["last_name"]=> array(2) {
[0]=> string(6) "Dodson"
[1]=> string(8) "McKenzie" }
["order"]=> array(2) {
[0]=> string(2) "1A"
[1]=> string(2) "1A" }
["movement"]=> array(2) {
[0]=> string(12) "Key Movement"
[1]=> string(12) "Key Movement" }
["rep_set_sec"]=> array(2) {
[0]=> string(17) "Sets/Reps/Seconds"
[1]=> string(17) "Sets/Reps/Seconds" }
["rest"]=> array(2) {
[0]=> string(4) "Rest"
[1]=> string(4) "Rest" }
}
これは、var_dump を実行したときにどのように見えるはずですか?
このようにするには、配列の各行が必要です。最初の 3 つの値は、user_id、class_id、および class_name であり、前のページの HTML フォームの一部ではありません。これらの値は、解析スクリプト ページで取得され、結果の各行と共に渡されます。
$row = array(29, 48, Class 1, Colby, Big Cheese, Dodson, 1A, Key Movement, Sets/Reps/Secons, Rest)
フォームのエントリごとに、このような行が必要です。