当前位置:首页 » 编程语言 » php多选题

php多选题

发布时间: 2022-10-29 08:35:30

Ⅰ 用php编写多道选择题输出的时候,怎么下面的name名称输出去。

你的代码唯一的错误就是<form>标签放在do while循环里面了。此外,对于你的需求使用while就好,不要用dowhile,如果你的sql返回0行不就错了么。

<form method="post" action="test.php">
<?php
session_start();
require "conn.php";
$sql=mysql_query("select * from test");
$i = 0;
?>
<?php while($info = mysql_fetch_array($sql)): $i ++;?>
<div><?php echo $i."、".$info['question'];?><br />

<input type="radio" name="<?php echo $info['questionid'];?> value="A" />A:<?php echo $info['key_a'];?>
<input type="radio" name=<?php echo $info['questionid'];?> value="B" />B:<?php echo $info['key_b'];?>
<input type="radio" name=<?php echo $info['questionid'];?> value="C" />C:<?php echo $info['key_c'];?>
<input type="radio" name=<?php echo $info['questionid'];?> value="D" />D:<?php echo $info['key_d'];?>
</div>
<?php endwhile;?>

<div>
<input type="submit" name="finish" value="完成" />
</div>
</form>

Ⅱ PHP处理多选数组问题

<?php
//判断是否提交(建立按钮)
if(isset($_POST['button'])){
//判断是del值是否已经设置
if(isset($_POST['deltype'])){
//把$_POST['deltype']数组转换成字符串
$str = implode(",",$_POST['deltype']);
//在页面输出内容
echo $str;
}

}

?>

<form id="form1" name="form1" method="post" action="">

<select name="deltype[]" size="5" multiple="multiple" id="deltype[]">

<option value="电费">电费</option><option value="水费">水费</option><option value="工资">工资</option><option value="火食费">火食费</option><option value="玩游戏赚的外快">玩游戏赚的外快</option>

</select>
<input type="submit" name="button" id="button" value="建立" />

</form>

把上面的代码保存成php文件就行

Ⅲ php 用explode()以”*”为分隔符实现添加多选题功能

$str = "1*2*3*4*5";
$arr=explode("*",$str);//结果$arr为组,$arr[0]=1,$arr[1]=2.....
var_mp($arr);//打印 内容

Ⅳ php多项选择问题

js可以实现,通过给每个链接一个ID,然后服务器端生成一个动态的变量,调用函数实现
考虑下面的代码:
考虑篇幅就省去了一些属性标记

<a href="#" id="a_1">A</a>
<a href="#" id="a_2">B</a>
<a href="#" id="a_3">C</a>
<script>
var s = 'a_<?php echo("1") ?>'
document.getElementById(s).style.background = '#f00';
</script>

试着拷贝上面的代码另存为php代码运行。看到关键点没,那个 echo 输出的 1,那么你可以通过$_GET获取一个变量并且输出,通过JS控制背景色或者其他什么效果,具体的你自己去实现了。另外,做前台这些效果,用jQuery比较好,我这只是一个例子,没有弄那么详细。

Ⅳ 用PHP做多项选择题,数据库怎么设计, 代码怎么写....

常规思路


表1(问题)

question

id(主键)text(问题内容)rightAnswer(正确答案)


表2(备选答案)

answer

id(主键)qid(对应的问题id)text(备选答案)


$sql="SELECT*FROMquestion";
$r=mysql_query($sql);
while($row=mysql_fetch_rows($r)){
//输出题干
echo$row[1];
$subsql="SELECT*FROManswerWHEREqid='".$row[0]."'";
$subr=mysql_query($subsql);
while($subrow=mysql_fetch_rows($subr)){
//输出备选答案
echosubrow[2];
}
}


我相信这是比较主流的设计思路,希望的帮到你


至于比对答案的时候,有一种简单做法,你传回来的答案不是数组吗,将数据库正确答案以字符串形式输出,打散成数组,求2个数组的交集,根据交集数量判断正确个数


不懂欢迎追问

Ⅵ php关于字符串的处理(考试多选题),有点难

<!doctypehtml>
<html>
<head>
<metacharset="UTF-8">
<title>UntitledDocument</title>
</head>
<formaction=""method="post">
正确答案:<inputtype="text"name='answer'>
答案:<inputtype="text"name="stuanswer">
<inputtype="submit"value="比较答案">
</form>
<?php
if(isset($_POST['answer'])&&isset($_POST['stuanswer'])&&$_POST['answer']!=''&&$_POST['stuanswer']!=''){
$str=$_POST['answer'];
$str1=$_POST['stuanswer'];
if(strlen($str1)==strlen($str)){
$count=strlen($str);
for($i=0;$i<$count;$i++){
if(!strstr($str1,$str[$i])||!strstr($str,$str1[$i])){
echo"<script>alert('答案错误');</script>";
exit;
}
}echo"<script>alert('答案正确');</script>";
}else{
echo"<script>alert('答案错误');</script>";
}
}
?>
<body>
</body>
</html>

//来试试这个代码,正则我不会,只能写这样的代码,你可以测试,我测试结果没有问题

Ⅶ PHP程序题:编写回答多项选择题的php程序,具体要求如下图

就帮你写一下好了 我的php文件名称是test.php 你可以改成自己的php文件名称 好像是4zuoy2.php

<!DOCTYPEhtml>
<htmllang="zh-cn">
<head>
<metacharset="UTF-8"/>
<title>测试</title>
</head>
<body>
<formaction="test.php"type="post">
<divclass="select-area">
<inputtype="checkbox"name="program[]"value="1"/>AJAX
<inputtype="checkbox"name="program[]"value="2"/>PHP
<inputtype="checkbox"name="program[]"value="3"/>FLASH
<inputtype="checkbox"name="program[]"value="4"/>ASP
<inputtype="checkbox"name="program[]"value="5"/>JSP
</div>

<divclass="submit-button">
<inputtype="submit"class="submit">确定</button>
</div>

</form>
</body>
</html>

<?php
!empty($_POST['program'])?$program=$_POST['program']:'';
if($program){
//遍历传递过来的是数组
if(in_array(2,$program)&&in_array(4,$program)&&in_array(5,$program)){
echo'正确';
}elseif(!in_array(2,$program)||!in_array(4,$program)||!in_array(5,$program)){
echo'回答不全!';
}else{
echo'错误!';
}
}
?>

Ⅷ Php随机的20个单选题,多选题和判断题如何获取答题者的答案

题目随机抽取,在表单里记录题目的id号,比如 input 的name 是qu_34,就表示题目id是34,php就可以通过对post的下标的获取,得出题目id为34,和数据库对比,得到答案是否正确

Ⅸ 提交PHP程序,解决多选题的分数判定问题:ABCD四个选项 选对得5分 少选得2分 错选得0分

摘要 可以用位运算来计算

Ⅹ PHP多选题

31: A B D
32: A B C D
33: A B

热点内容
问道ios脚本辅助 发布:2025-07-14 02:54:40 浏览:716
安全的linux 发布:2025-07-14 02:48:39 浏览:91
我的世界好的极限生存服务器 发布:2025-07-14 02:34:59 浏览:997
c语言格式错误 发布:2025-07-14 02:34:51 浏览:529
xp系统清理缓存文件夹 发布:2025-07-14 02:29:09 浏览:871
编译并运行以下程序的结果是 发布:2025-07-14 02:28:22 浏览:591
java的业务流程 发布:2025-07-14 02:25:23 浏览:352
linuxprocess 发布:2025-07-14 02:24:36 浏览:808
手机版服务器生存有什么好玩的服务 发布:2025-07-14 01:49:45 浏览:210
锐龙3代编程 发布:2025-07-14 01:48:22 浏览:968