0

HTML 形式の質問がいくつかある php ページがあります。各質問には「タイプ」があり、その質問に 1 ~ 5 のスケールで回答します。以下の例では、A、B、& の 3 つの質問タイプがあります。 C. 各質問「タイプ」の合計スコア (スコアは各質問の下の 1 ~ 5 スケールのラジオ ボタンから作成されます) を追加し、それらの合計スコアを PHP 変数として保存するにはどうすればよいですか?

ここに HTML コードがあります。どこから始めればよいかわかりませんが、学校のイベントのためにこれを作成する必要があり、彼らをがっかりさせたくありません :) ハハ! 助けてくれてありがとう、申し訳ありませんが、私は HTML フォームについてほとんど知りません! とにかく、ここに HTML コードがあります。php は、まだ書いていないところならどこにでも移動できます /: ハハ:

Type A rating:
<br>
<form action="" method="post">
1
<input type="radio" name="select" value="1">
<input type="radio" name="select" value="2">
<input type="radio" name="select" value="3">
<input type="radio" name="select" value="4">
<input type="radio" name="select" value="5">
5
</form>
<br><br>
Type B rating:
<br>
<form action="" method="post">
1
<input type="radio" name="select" value="1">
<input type="radio" name="select" value="2">
<input type="radio" name="select" value="3">
<input type="radio" name="select" value="4">
<input type="radio" name="select" value="5">
5
</form>
<br><br>
Type A rating:
<br>
<form action="" method="post">
1
<input type="radio" name="select" value="1">
<input type="radio" name="select" value="2">
<input type="radio" name="select" value="3">
<input type="radio" name="select" value="4">
<input type="radio" name="select" value="5">
5
</form>
<br><br>
Type C rating:
<br>
<form action="" method="post">
1
<input type="radio" name="select" value="1">
<input type="radio" name="select" value="2">
<input type="radio" name="select" value="3">
<input type="radio" name="select" value="4">
<input type="radio" name="select" value="5">
5
</form>
<br><br>
Type A rating:
<br>
<form action="" method="post">
1
<input type="radio" name="select" value="1">
<input type="radio" name="select" value="2">
<input type="radio" name="select" value="3">
<input type="radio" name="select" value="4">
<input type="radio" name="select" value="5">
5
</form>
<br><br>
Type B rating:
<br>
<form action="" method="post">
1
<input type="radio" name="select" value="1">
<input type="radio" name="select" value="2">
<input type="radio" name="select" value="3">
<input type="radio" name="select" value="4">
<input type="radio" name="select" value="5">
5
</form>
<br><br>
Type B rating:
<br>
<form action="" method="post">
1
<input type="radio" name="select" value="1">
<input type="radio" name="select" value="2">
<input type="radio" name="select" value="3">
<input type="radio" name="select" value="4">
<input type="radio" name="select" value="5">
5
</form>
<br><br>

<input type="submit" name="Sum The Ratings" value="Vote">
4

1 に答える 1

2

すべての質問を含む大きなフォームを作成し、質問ごとに、質問ごとに異なるキーワードを使用して入力の名前を設定します。フォームを処理するとき、選択した値を $_POST['name'] で取得します。それらを追加して配給するか、必要のないものを作成します

<?php
$name_cat_a = "A_";
$name_cat_b = "B_";
$cat_a_quest = array("Question A1", "Question A2");
$cat_b_quest = array("Question B1", "Question B2");
if(!isset($_POST[submit])){
echo '<form action="test.php" method=post>';
echo 'Type A rating:';
echo '<br />';
$ind = 0;
foreach($cat_a_quest as $question){
    echo $question;
    echo '<br>';
    $name = $name_cat_a . $ind;
    $ind ++;
    for($i=0;$i<5;$i++){
    echo '<input type="radio" name="'.$name.'" value="'.($i+1).'" />'.($i+1) ;
    }
    echo '<br />';
}
echo 'Type B rating:';
echo '<br />';
$ind = 0;
foreach($cat_b_quest as $question){
    echo $question;
    echo '<br>';
    $name = $name_cat_b . $ind;
    $ind ++;
    for($i=0;$i<5;$i++){
    echo '<input type="radio" name="'.$name.'" value="'.($i+1).'" />'.($i+1);
    }
    echo '<br />';
}
echo '<input type="hidden" name="submit" value="1" />';
echo '<input type="submit" name="Sum The Ratings" value="Vote">';
echo '</form>';
}
else{
$moyen_a = 0;
$moyen_b = 0;
$nmb_ques_a = count($cat_a_quest);
$nmb_ques_b = count($cat_b_quest);
for($i=0; $i<$nmb_ques_a; $i++){
     $moyen_a = $moyen_a + intval($_POST['A_'.$i]);
}
$moyen_a = $moyen_a / $nmb_ques_a;
for($i=0; $i<$nmb_ques_b; $i++){
     $moyen_b = $moyen_b + intval($_POST['B_'.$i]);
}
$moyen_b = $moyen_b / $nmb_ques_b;


echo 'A:'.$moyen_a.'<br />';
echo 'B:'.$moyen_b.'<br />';
}
?>

そこに明示的に cat_a と cat_b という名前を付けましたが、すべての猫を配列に入れてループし、このループで質問がある間にループし、5 つの回答をループします。

于 2012-02-19T03:25:23.420 に答える