Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > PHP > PHP Forum > ต้องการสุ่มข้อสอบ โดยสุ่มมาแค่ 5 ข้อ เอาแบบสุ่มไม่ซ้ำกันด้วยน่ะครับ ขอ code ด้วยครับ



 

ต้องการสุ่มข้อสอบ โดยสุ่มมาแค่ 5 ข้อ เอาแบบสุ่มไม่ซ้ำกันด้วยน่ะครับ ขอ code ด้วยครับ

 



Topic : 020896

Guest




เอาแบบสุ่มไม่ซ้ำกันด้วยน่ะครับ ขอ code ด้วยครับ


Tag : - - - -







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 7 ก.ค. 2551 17:26:54 By : กำลังทำแบบทดสอบครับ View : 8030 Reply : 14
 

 

No. 1

Guest


select rand(field_name) from table;






Date : 7 ก.ค. 2551 18:10:36 By : 111
 


 

No. 2

Guest


select * from table where 1 order by rand() limit 6
Date : 7 ก.ค. 2551 18:22:55 By : อิอิ
 

 

No. 3

Guest


ถ้าสุ่ม คำตอบให้เลือกอีก ข้อละ 4 คำตอบหล่ะครับ ทำไง
ต้องแยกตารางเก็บ คำถามและคำตอบ ด้วยป่าว
ทำไงครับ มี code ไหม
Date : 9 ก.ค. 2551 11:49:57 By : ak47
 


 

No. 4

Guest


ak47 แยกตารางเก็บครับ
Date : 9 ก.ค. 2551 18:13:31 By : อิอิ
 


 

No. 5

Guest


<html>
<body>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874">
<br><br><form name="form1" method="post" action="answertestless1.php">
<?
$host="localhost";
$username="";
$password="";
$db="mydatabase";
$tb="testing";
mysql_connect( $host,$username,$password) or die ("ติดต่อกับฐานข้อมูล Mysql ไม่ได้ ");
mysql_select_db($db) or die("เลือกฐานข้อมูลไม่ได้");
$sql="Select * From $tb order by rand() limit 5";
$db_query=mysql_query($sql);
$i=0;
while($result=mysql_fetch_array($db_query))
{
$i++;
?>
<table width="200%" border="0" align="center">
<tr>
<td width="30%"> <div align="left">
o<input name="id[<?=$i;?>]" type="hidden" value="<?=$result["id"];?>">
<?=$result["question"];?></div>
</div></td>
<td width="14%"> <input name="c<?=$i;?>" type="radio" value="1" checked>
<?=$result["c1"];?>
</td>
<td width="16%"> <input type="radio" name="c<?=$i;?>" value="2">
<?=$result["c2"];?>
</td>
<td width="16%"> <input type="radio" name="c<?=$i;?>" value="3">
<?=$result["c3"];?>
</td>
<td width="15%"> <input type="radio" name="c<?=$i;?>" value="4">
<?=$result["c4"];?>
<input name="answer[<?=$i;?>]" type="hidden" value="<?=$result["answer"];?>">
</td>
</tr>
</table>
<?
}
mysql_close();
?>
<div align="center"><br>
<input type="submit" name="Submit" value="ตรวจคะแนน">
</div>
</form>
</body>
</html>



อย่าลืมสร้างฐานข้อมูลก่อนนะ
Date : 27 ส.ค. 2551 18:03:06 By : acyber_g
 


 

No. 6



โพสกระทู้ ( 17 )
บทความ ( 0 )



สถานะออฟไลน์


ทำแบบตัวอย่างด้านบน สุ่มได้แล้ว แต่ตรวจคะแนนไม่ได้อะ
มันต้องเช็คกับตัวไหนบ้างอะ
ขอความกรุณาบอกหน่อยนะค่ะ
ขอบคุณคะ
Date : 2010-05-04 14:38:02 By : rin032
 


 

No. 7

Guest


คุณ rin032 มีไฟล์ให้ดูไหมค่ะ จะได้เช็คให้ถูก ต้องดูโครงสร้างด้วยนะค่ะ ส่งมาบอกทางเมล์ก็ได้นะค่ะ

เผื่อไม่ได้เข้ามาในเว็บนะค่ะ
Date : 2010-05-05 14:38:08 By : [email protected]
 


 

No. 8



โพสกระทู้ ( 98 )
บทความ ( 0 )



สถานะออฟไลน์


https://www.thaicreate.com/php/forum/016807.html
https://www.thaicreate.com/php/forum/007652.html
ข้อสอบ
Code (PHP)
<?php
include('connect.php');

$sql="select*from qq order by rand() limit 3 ";
$result=mysql_query($sql,$con);
$number=0;
?>
<table align="center" width="780" cellpadding="0" cellspacing="0">
<tr> 
<td><div id="header">ข้อสอบ</div></td>
</tr>
<tr><td>
<div id="maintain"><form action="check_answer.php" method="post">
  <table align="center" width="780" border="1">
   <? 
while($arr=mysql_fetch_array($result)){
	
	$id=$arr['id'];
	$question=$arr['data'];
	$choice1=$arr['ans1'];
	$choice2=$arr['ans2'];
	$choice3=$arr['ans3'];
	$number++;
	$i++;
echo "<tr>
<td>
 $number
</td>
<td> $question</td>
<td> 
<input type='radio' name='select_$id'  value='1'>
$choice1
<input type='radio' name='select_$id'  value='2'>
$choice2
<input type='radio' name='select_$id'  value='3'> 
$choice3
<input type='hidden' name='total_question[]' value='$id'<br>
</td>
</tr>";
}
?>
    <tr>
      <td  colspan="3"><input type="submit" value="click"  /><input type="reset" value="reset" /></td>
    </tr>
    <tr>
      <td></td>
    </tr>
  </table>
  </form>
  </div>
  </td>
  </tr>
  <tr><td>&nbsp;</td></tr>
  </table>


ตรวจคำตอบ
Code (PHP)
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?
$correct=0;
$total=count($total_question);
echo $total."<br>";
include('connect.php');
$sql="select id, ans_true from qq order by id";
$result=mysql_query($sql);
while ($ar=mysql_fetch_array($result)){
$id=$ar['id'];
$answer=$ar['ans_true'];

if (in_array($id, $total_question)){
	
$select="select_".$id;
if (${$select}==$answer) {
$correct++;
}
}
}
echo "ตอบถูก ทั้งหมด $correct <br> คำถามทั้งหมด $total";

?>

ปล . ถ้า search หาสักนิดก็จะเจอครับ
Date : 2010-05-05 17:21:34 By : sagi
 


 

No. 9



โพสกระทู้ ( 17 )
บทความ ( 0 )



สถานะออฟไลน์


มีเรื่องรบกวนหน่อยคะ
พอดีว่าต้องการทำข้อสอบแบบสุ่ม ให้สุ่มออกมาเป็นชุดนะคะ
ข้อสอบทั้งหมดมี30ข้อ อยากให้มันดึงออกมาครั้งละ 10 ข้อ
หมายถึง ครั้งที1ให้ดึงข้อ 1-10
ครั้งที่ 2 ให้ดึงข้อ11-20
ครั้งที่3 ให้ดึงข้อ21-30
ครั้งที่4 ให้วนกลับไปเหมือนรอบที่1นะคะ คือข้อ1-10
ใครมีโค้ดบ้างรบกวนช่วยบอกหน่อยได้ไหมคะ
ใกล้ถึงกำหนดส่งแล้วแต่ยังทำข้อสอบไม่ได้เลย
หรือจะส่งมาทาง เมล์ก็ได้นะคะ [email protected]
ขอบคุณล่วงหน้าค่ะ
Date : 2010-06-15 10:49:10 By : rin032
 


 

No. 10



โพสกระทู้ ( 17 )
บทความ ( 0 )



สถานะออฟไลน์


คุณGuestค่ะ มีตัวอย่างการสุ่มข้อสอบออกมาเป็นชุดบ้างไหมค่ะ
Date : 2010-06-15 10:50:40 By : rin032
 


 

No. 11



โพสกระทู้ ( 46 )
บทความ ( 0 )



สถานะออฟไลน์


ห้ามทำข้อสอบซ้ำ ทำไงค่ะ เราจะดักที่ตรงไหน
Date : 2012-07-07 15:11:14 By : jutathipphp
 


 

No. 12



โพสกระทู้ ( 145 )
บทความ ( 0 )



สถานะออฟไลน์


pretest.php
Code (PHP)
<form name="form1" method="post" action="confirm3.php">
<?
$host="localhost";
$username="root";
$password="1234";
$db="database";
$tb="testing";
mysql_connect( $host,$username,$password) or die ("ติดต่อกับฐานข้อมูล Mysql ไม่ได้ ");
mysql_select_db($db) or die("เลือกฐานข้อมูลไม่ได้");
mysql_query("SET character_set_results=tis620");
mysql_query("SET character_set_client=tis620");
mysql_query("SET character_set_connection=tis620");
$sql="Select * From $tb order by id limit 50";
$db_query=mysql_query($sql);
$i=0;
while($result=mysql_fetch_array($db_query))
{
$i++;
?>
<table width="64%" border="0" align="center">
<tr>
<td width="18%"> <div align="left">
<input name="id<?=$i;?>" type="hidden" value="<?=$result["id"];?>">
<?=$result["question"];?>
</div></td>
</tr>
<tr>
  <td><input name="c<?=$i;?>" type="radio" value="1" checked>
    <?=$result["c1"];?></td>
  </tr>
<tr>
  <td><input type="radio" name="c<?=$i;?>" value="2">
    <?=$result["c2"];?></td>
  </tr>
<tr>
  <td><input type="radio" name="c<?=$i;?>" value="3">
    <?=$result["c3"];?></td>
  </tr>
<tr>
  <td><input type="radio" name="c<?=$i;?>" value="4">
    <?=$result["c4"];?>
    <input name="answer<?=$i;?>" type="hidden" value="<?=$result["answer"];?>"></td>
  </tr>
</table><br>
<?
}
mysql_close();
?>
<div align="center"><br>
<input type="hidden" name="line" value="<?=$i;?>">
<input type="submit" name="Submit" value="ตรวจคะแนน">
</div>
</form>


confirm3.php //ตรวจข้อสอบ มียืนยันข้อสอบ

Code (PHP)
<form name="form1" method="post" action="updateconfirm3.php">
      <div align="center">
        <p><?
$score=0;
for($i=1;$i<=$_POST["line"];$i++)
{
	If($_POST["c$i"] == $_POST["answer$i"])
	{
			$score=$score+1;
	}
}
echo "<p align='center'>คุณทำข้อสอบได้ $score คะแนนจาก 30 ข้อ<br>";

?></p>
        <table width="182" border="0" bgcolor="#0094DE">
          <tr>
            <td width="176"><div align="center"><span class="style16">คลิกยืนยันสถานะผ่านการทดสอบ</span></div></td>
          </tr>
        </table>
          <br>
        <table width="200" border="0">
          <tr>
            <td><div align="center">
              <select name="txtConfirm" id="txtConfirm"  value="<?=$objResult["Sex"];?>">
                <option value="1">ผ่านการทดสอบก่อนเรียนแล้ว</option>
              </select>
            </div></td>
          </tr>
        </table>
              <label>
        <select name="txtScore3" id="txtScore3">
		<option value="<?php echo"$score"; ?>">คุณทำข้อสอบได้ <?php echo"$score"; ?> คะแนน</option>
        </select>
        </label><br>
          <input type="submit" name="Submit" value="ยืนยัน">
      </div>
    </form>



updateconfirm3.php
Code (PHP)
<?
	session_start();
	if($_SESSION['UserID'] == "")
	{
		echo "Please Login!";
		exit();
	}
	mysql_connect("localhost","root","1234");
	mysql_select_db("database");
			mysql_query("SET character_set_results=tis620");
mysql_query("SET character_set_client=tis620");
mysql_query("SET character_set_connection=tis620");
	
	if($_POST["txtPassword"] != $_POST["txtConPassword"])
	{
		echo "ÃËÑʼèÒ¹äÁèµÃ§¡Ñ¹!";
		exit();
	}
	$strSQL = "UPDATE member SET Confirm = '".trim($_POST['txtConfirm'])."',Score3 = '".trim($_POST['txtScore3'])."' WHERE UserID = '".$_SESSION["UserID"]."' ";
	$objQuery = mysql_query($strSQL);
	header ("Location:contentmain.php"); 
		
	

	mysql_close();
?>


อันนี้ไม่เป็นชุดนะคะ เอาเป็นแนวละกันค่ะ
ของเราจะมียืนยันการทำข้อสอบ แล้วส่งค่าไปฐานข้อมูล คือเก็บคะแนน และ สถานะการทำข้อสอบแล้ว เป็น1

ลองๆแปลงนะคะ


ประวัติการแก้ไข
2012-07-07 19:18:03
2012-07-07 19:19:15
Date : 2012-07-07 19:16:01 By : นู๋น้อย
 


 

No. 13



โพสกระทู้ ( 145 )
บทความ ( 0 )



สถานะออฟไลน์


ห้าทำข้อสอบซ้ำ ก็ ใช้ if ธรรมดาดักเลยค่ะ ไม่มีปัญหาเลย แต่ของเราทำแล้ว ให้เด้งเข้าบทเรียนเลย
Date : 2012-07-07 19:22:36 By : นู๋น้อย
 


 

No. 14



โพสกระทู้ ( 46 )
บทความ ( 0 )



สถานะออฟไลน์


ขอบคุณมากๆค่ะ
Date : 2012-07-11 00:13:42 By : jutathipphp
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : ต้องการสุ่มข้อสอบ โดยสุ่มมาแค่ 5 ข้อ เอาแบบสุ่มไม่ซ้ำกันด้วยน่ะครับ ขอ code ด้วยครับ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 02
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่