针对各种类别问题的单选按钮评分系统,并在末尾添加分数

发布于 2025-01-07 07:49:28 字数 2873 浏览 1 评论 0原文

我有一个 php 页面,上面有一些 HTML 问题,每个问题都有一个“类型”,您以 1-5 的范围回答该问题,在下面的示例中将有 3 种问题类型:A、B 和 & ; 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">

I have a php page that has a few HTML questions on it, each question has a "type" and you answer that question on a scale of 1-5, In the example below there would be 3 question types: A, B, & C. How can I add the TOTAL score for each question "type"(score is made from the radio buttons for the 1-5 scale below each question) and then have those total scores stored as PHP variables?

Here is the HTML code, I have NO CLUE where to start but I need to make this for a school event we are doing soon and I don't wanna let them down :) Haha! Thanks for all the help guys, sorry I know so little about HTML forms! Anyways, here's the HTML code, the php can go anywhere I haven't written it yet /: haha:

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">

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

2025-01-14 07:49:28

创建一个包含所有问题的大表单,然后对于每个问题,使用每个问题不同的关键字设置输入名称。当你处理你的表单时,你将得到 $_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 个答案

Create a big form with all the questions in it, then for each question, set the name of the input with a keyword different for each questions. When you will treat your form, you will get with $_POST['name'] the value selected, just add them and make a ration or wathever you wan't

<?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 />';
}
?>

There i have explicitely name cat_a and cat_b but you can put all your cat in an array, then you loop into it, in this loop, you loop while ther is questions, and then you loop for the 5 answers

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文