php多選題
Ⅰ 用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