php+mysql 개발 의 가장 간단 한 온라인 문제 라 이브 러 리(온라인 문제 풀이 시스템)전체 사례

본 고 는 php+mysql 개발 의 가장 간단 한 온라인 문제 라 이브 러 리 를 실례 로 서술 하 였 다.여러분 께 참고 하도록 공유 하 겠 습 니 다.구체 적 으로 는 다음 과 같 습 니 다.
문제 고 는 교육 기구,학교,온라인 교육 에 있어 필요 하 다.인터넷 에 도 제3자 온라인 문제 창고 시스템 이 적지 않다.그러나 이번 사례 는 필요 한 사람 에 게 문제 창고 의 개발 방향 을 이해 하 게 할 것 이다.사실은 매우 간단 하 다.단지 하나의 폼 검증,데이터 창고 검증 일 뿐이다.
1.폼 데이터 구축
2.폼 데 이 터 를 get 또는 post 방식 으로 폼 인증 페이지 에 제출 하여 데이터베이스 와 일치 시 킵 니 다.
3.결 과 를 되 돌려 주 고 정 답 또는 오류
빌 드 폼:
index.php

<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" />
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  <meta name="format-detection" content="telephone=no">
  <title>  </title>
  <style type="text/css">
    *{list-style: none;margin:0px;padding: 0px;}
    #tiku{
      width: 300px;
      margin:10px auto;
    }
    #tiku ul li{
      float: left;
    }
  </style>
</head>
<body>
<?php
//       
require_once("config.php");
//     
$con = mysql_connect($host,$username,$password);
//         
mysql_query("SET NAMES UTF8");
//     
mysql_select_db($db, $con);
//     
//     1   
$all = mysql_num_rows(mysql_query("select * from $tb"));
//         
$lenght=1;               //       
@$page=$_GET['page']?$_GET['page']:1;  //   
$offset=($page-1)*$lenght;       //       
$allpage=ceil($all/$lenght);      //     -   
$prepage=$page-1;            //       
if($page==1){
  $prepage=1;             //        1      1
  }
$nextpage=$page+1;
if($page==$allpage){
  $nextpage=$allpage;        //                    
  }
$sql="select * from $tb order by id ASC limit {$offset},{$lenght}";
$rest=mysql_query($sql);
while($row = mysql_fetch_assoc($rest))
  {
    $id = $row["id"];
    $title = $row["title"];
    $A = $row["answer_A"];
    $B = $row["answer_B"];
    $C = $row["answer_C"];
    $D = $row["answer_D"];
    $true = $row["true"];
    $score = $row["score"];
  }
?>
<div id="tiku">
  <form action="check.php" method="get">
    <p><?php echo $title;?></p>
    <input type="radio" name="xuanxiang" value="<?php echo $A;?>">A:<?php echo $A;?><br>
    <input type="radio" name="xuanxiang" value="<?php echo $B;?>">B:<?php echo $B;?><br>
    <input type="radio" name="xuanxiang" value="<?php echo $C;?>">C:<?php echo $C;?><br>
    <input type="radio" name="xuanxiang" value="<?php echo $D;?>">D:<?php echo $D;?><br><br>
    <input type="hidden" name="id" value="<?php echo $id;?>">
    <button>  </button>
  </form>
</div>
  <br/>
  <?php
  echo "<div id='tiku'>";
    echo "<ul>";
      echo "<li><a href='next.php?page=$prepage'>   </a></li>";
      echo "<li><a href='next.php?page=$nextpage'>   </a></li>";
    echo "</ul>";
  echo "<div>";
  echo "<br/>";
  echo "<p class='fenye_tips'> ".$allpage."  ,    ".$page." </p>";
  echo "<br/><br/>";
  echo "</div>";
  ?>
</body>
</html>

양식 접수
check.php

<?php
header("Content-type:text/html;charset=utf-8");
//       
require_once("config.php");
//     
$con = mysql_connect($host,$username,$password);
//         
mysql_query("SET NAMES UTF8");
//     
mysql_select_db($db, $con);
//    
$xuanxiang = $_GET["xuanxiang"];
$id = $_GET["id"];
if (empty($xuanxiang)) {
  echo "<script>alert('       !');history.go(-1);</script>";
}else{
  //     
  $result = mysql_query("SELECT * FROM $tb WHERE id =".$id);
  while($row = mysql_fetch_array($result))
  {
    $true = $row["true"];
    $next_id = $id+1;
    if($xuanxiang == $true){
      echo "<script>alert('  ! 5 !');location.href='next.php?page=$next_id';</script>";
    }else{
      echo "<script>alert('  ! 5 !');history.go(-1);</script>";
    }
  }
}
?>

데이터베이스 설정
config.php

<?php
//     - BY TANKING
$host="     ";
$username="  ";
$password="  ";
$db="    ";
$tb = "  ";
?>

next.php
다음 문제

<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" />
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  <meta name="format-detection" content="telephone=no">
  <title>  </title>
  <style type="text/css">
    *{list-style: none;margin:0px;padding: 0px;}
    #tiku{
      width: 300px;
      margin:10px auto;
    }
    #tiku ul li{
      float: left;
    }
  </style>
</head>
<body>
<?php
//       
require_once("config.php");
//     
$con = mysql_connect($host,$username,$password);
//         
mysql_query("SET NAMES UTF8");
//     
mysql_select_db($db, $con);
//     
//     1   
$all = mysql_num_rows(mysql_query("select * from $tb"));
//         
$lenght=1;               //       
@$page=$_GET['page']?$_GET['page']:1;  //   
$offset=($page-1)*$lenght;       //       
$allpage=ceil($all/$lenght);      //     -   
$prepage=$page-1;            //       
if($page==1){
  $prepage=1;             //        1      1
  }
$nextpage=$page+1;
if($page==$allpage){
  $nextpage=$allpage;        //                    
  }
$sql="select * from $tb order by id ASC limit {$offset},{$lenght}";
$rest=mysql_query($sql);
while($row = mysql_fetch_assoc($rest))
  {
    $id = $row["id"];
    $title = $row["title"];
    $A = $row["answer_A"];
    $B = $row["answer_B"];
    $C = $row["answer_C"];
    $D = $row["answer_D"];
    $true = $row["true"];
    $score = $row["score"];
  }
?>
<div id="tiku">
  <form action="check.php" method="get">
    <p><?php echo $title;?></p>
    <input type="radio" name="xuanxiang" value="<?php echo $A;?>">A:<?php echo $A;?><br>
    <input type="radio" name="xuanxiang" value="<?php echo $B;?>">B:<?php echo $B;?><br>
    <input type="radio" name="xuanxiang" value="<?php echo $C;?>">C:<?php echo $C;?><br>
    <input type="radio" name="xuanxiang" value="<?php echo $D;?>">D:<?php echo $D;?><br><br>
    <input type="hidden" name="id" value="<?php echo $id;?>">
    <button>  </button>
  </form>
</div>
  <br/>
  <?php
  echo "<div id='tiku'>";
    echo "<ul>";
      echo "<li><a href='next.php?page=$prepage'>   </a></li>";
      echo "<li><a href='next.php?page=$nextpage'>   </a></li>";
    echo "</ul>";
  echo "<div>";
  echo "<br/>";
  echo "<p class='fenye_tips'> ".$allpage."  ,    ".$page." </p>";
  echo "<br/><br/>";
  echo "</div>";
  ?>
</body>
</html>

데이터베이스 구조
제목
answer_A---정 답 A
answer_B---정 답 B
answer_C---정 답 C
answer_D---정 답 D
정 답
득점

더 많은 PHP 관련 내용 에 관심 이 있 는 독자 들 은 본 사이트 의 주 제 를 볼 수 있다.
본 논문 에서 말 한 것 이 여러분 의 PHP 프로 그래 밍 에 도움 이 되 기 를 바 랍 니 다.

좋은 웹페이지 즐겨찾기