20セットのフィールドを含むHTMLフォームがあります。例として2つあります。
<input type="text" class="auto-clear" id="p1weight" name="p1weight" value="" />
<input type="text" class="auto-clear" id="p1length" name="p1length" value="" />
<input type="text" class="auto-clear" id="p1width" name="p1width" value="" />
<input type="text" class="auto-clear" id="p1height" name="p1height" value="" />
<input type="text" class="auto-clear" id="p2weight" name="p2weight" value="" />
<input type="text" class="auto-clear" id="p2length" name="p2length" value="" />
<input type="text" class="auto-clear" id="p2width" name="p2width" value="" />
<input type="text" class="auto-clear" id="p2height" name="p2height" value="" />
次のPHPコードを使用して、フィールド値を格納する文字列( $ all )を生成しています。
foreach( range( 1, 20) as $i)
{
// Create an array that stores all of the values for the current number
$values = array(
'p' . $i . 'weight' => $_POST['p' . $i . 'weight'],
'p' . $i . 'length' => $_POST['p' . $i . 'length'],
'p' . $i . 'width' => $_POST['p' . $i . 'width'],
'p' . $i . 'height' => $_POST['p' . $i . 'height']
);
$all .= implode( '|', $values) . "\n\n";
}
2セットのフィールドへの入力が1、2、3、4の場合、$allの値は次のようになります1|2|3|4 1|2|3|4
。
ただし、これをさらにカスタマイズしたいと思います。最終的には、 $allを次のようにしたいと思います。
Item1: Weight (kg):1 Length (cm): 2 Width (cm): 3 Height (cm): 4
Item2: Weight (kg):1 Length (cm): 2 Width (cm): 3 Height (cm): 4
これを実現するために上記のPHPを更新するにはどうすればよいですか?
ポインタをありがとう。