調查問卷資料庫設計

Coding-lover發表於2015-11-01

表格:使用者表—選用網站使用者表
問卷表—包含調查問卷自動編號、標題、前言、開啟時間、結束時間、建立時間
問題表—包含問題編號、問題標題、相應的問卷編號、問題型別
選項表—包含選項編號、選項值、選項對應的問題、對應的問卷
答案表—使用者編號、問卷編號、問題編號、答案內容
注:對於多選問題,每一條答案記錄一條記錄
統計:進行資料統計時,每一條答案記錄統計一次,統計條件:

select * from `table_name` where  answer_proid  = `problem_id` and answer_quesid = `question_id` and answer_value = 'A' group by answer_proid;

對於多選的數值提交:
前臺頁面:

     <input type="hidden" id="i" name="i" value="<?php echo $i;?>"/>
     <p><?php echo $i."、".$rows['problem_title'];?></p>
     <input type="hidden" id="pro<?php echo $i?>" name="pro<?php echo $i?>" value="<?php echo $rows['problem_id']?>"/>
     <input type='hidden' id="protype<?php echo $i;?>" name="protype<?php echo $i;?>" value="<?php echo $protype;?>"/>
     <?php
         $sql2="select * from jinling_option where option_proid=".$rows['problem_id'];
           $result2=mysql_query($sql2);
           $nums=mysql_num_rows($result2);
           if($nums>0){
              while($row2=mysql_fetch_assoc($result2)){
                if($protype=="1"){
                 $btntype="radio";
               ?>
              <p style="margin-left:20px;">
              <input type="<?php echo $btntype;?>" id="radiopt<?php echo $i;?>" name="radiopt<?php echo $i;?>" value="<?php echo $row2['option_value'];?>">
               <?php echo $row2['option_content'];?>
             </p>   
             <?php
              }
              if($protype=="2"){
                $btntype="checkbox";
               ?>
              <p style="margin-left:20px;">
              <input type="<?php echo $btntype;?>" id="option[]" name="option[]" value="<?php echo $row2['option_value'];?>">
              <?php echo $row2['option_content'];?>
            </p>
        <?php
    }
  }
  }
  ?>

後臺資料接收:

    for($y=1;$y<=$i;$y++){
    $proid=sqlReplace(trim($_POST['pro'.$y]));
    $protype=sqlReplace(trim($_POST['protype'.$y]));
    if($protype=="1"){
     $option = sqlReplace(trim($_POST['radiopt'.$y]));
     $sql2="insert into jinling_answer (answer_proid,answer_user,answer_time,answer_quesid,answer_content)values(".$proid.",".$user_id.",now(),".$quesid.",'".$option."')";
     //echo $sql2;
      mysql_query($sql2);
    }elseif($protype=="2"){
    for($a=0;$a<count($_POST['option']);$a++){
    $option2 = sqlReplace(trim($_POST['option'][$a]));
     $sql3="insert into jinling_answer (answer_proid,answer_user,answer_time,answer_quesid,answer_content)values(".$proid.",".$user_id.",now(),".$quesid.",'".$option2."')";
   //echo $sql3;
    mysql_query($sql3);
 }
 }
}
 alertInfo("問卷提交成功",'survey.php',0);

關於動態新增html元素的js:

<script type="text/javascript">

var count = 2;
var myopt = new Array('A','B','C','D','E','F','G','H');
function Add(){
   count += 1;
   var opt = myopt[count-1];
   var File1 = document.getElementByIdx_x_x("quetype");
   var p = document_createElement_x_x("p");

   var inputTxt = document_createElement_x_x("input");
   inputTxt.type = "text";
   inputTxt.name = "optionname"+count;
   inputTxt.id = "optionname"+count;
   inputTxt.value = "";

   var inputhi = document_createElement_x_x("input");
   inputhi.type="hidden";
   inputhi.value=opt;
   inputhi.id="option"+count;
   inputhi.name="option"+count;

   var countopt = document_createElement_x_x("input");
   countopt.type="hidden";
   countopt.id="countopt";
   countopt.name="countopt";
   countopt.value=count;

   var btn = document_createElement_x_x("input");
   btn.type = "image";
   btn.src="images/add.gif";
   btn.onclick = function(){
       Add(this);
       return false;
   }

   p.a(inputhi);
   p.a(countopt);
   p.a(inputTxt);
   p.a(btn);
   File1.a(p);
}

</script>

相關文章