原生PHP開發簡易的問卷系統
題目要求
(1)問卷一覽:展示相應問卷,並可針對問卷執行建立、編輯、刪除等操作。
(2)問卷建立與編輯:建立新問卷或編輯已有問卷:
(3)問卷需要有標題、描述和可任意增減的調查條目。
(4)調查條目支援基礎文字形式以及以下至少一種特殊形式:
Ⅰ:Drop down list
Ⅱ:Radio button
Ⅲ:Checkbox
(5)問卷釋出:以連結或類似方式釋出問卷,供其他人訪問。
(6)問卷填寫:使用生成的問卷連結開啟問卷,並填寫相關資訊。
(7)問卷統計與匯出:對於已釋出的問卷,檢視問卷填寫的統計資料,並支援問卷資料的匯出。
技術與UI設計
(1)開發語言:PHP
(2)資料庫和工具:MySQL和資料庫視覺化工具Navicat for MySQL
(3)開發環境:Apache+PHP+mysql
(4)UI設計:採用bootstrap前端框架 https://v3.bootcss.com/
設計模式
MVC結構+面向物件程式設計
程式碼結構
註解:
- 頁面放在根目錄下,其中,
public>top.phtml
是導航欄 controller
檔案下的xxxcontroller.php
檔案是後端控制程式碼controller
檔案下HomeServics.php
是方法整合檔案controller
檔案下xxxDao.php
是資料庫工具類PHPEXCEL
資料夾下是工具類,可以從官網下載,操作excel檔案
PHPEXCEL
參考文件:https://www.cnblogs.com/wuxiumu/p/13390044.html
使用方法:
(1)先找到php7.0.9
資料夾下的php.ini
mbstring.func_overload
並註釋;(2)重啟Apache
系統設計
功能模組設計
資料庫表關係圖
表結構設計
SQL建表語句
-- ---------------------------- -- Table structure for `test` -- ---------------------------- DROP TABLE IF EXISTS `test`; CREATE TABLE `test` ( `Id` int(11) NOT NULL AUTO_INCREMENT, `QuestName` varchar(1024) DEFAULT NULL COMMENT '總標題', `QuestDescription` varchar(1024) DEFAULT NULL COMMENT '描述', `TitleCount` varchar(1024) DEFAULT NULL COMMENT '題序號', `TitleTitle` varchar(1024) DEFAULT NULL COMMENT '小標題', `Type` varchar(1024) DEFAULT NULL COMMENT '型別', `TitleA` varchar(1024) DEFAULT NULL, `TitleB` varchar(1024) DEFAULT NULL, `TitleC` varchar(1024) DEFAULT NULL, `TitleD` varchar(1024) DEFAULT NULL, `TitleId` tinyint(10) DEFAULT NULL COMMENT '題Id', `CreatBy` tinyint(10) DEFAULT NULL COMMENT '建立人', `Active` tinyint(2) DEFAULT '1' COMMENT '可用狀態', PRIMARY KEY (`Id`) ) ENGINE=InnoDB AUTO_INCREMENT=56 DEFAULT CHARSET=utf8; -- ---------------------------- -- Table structure for `user` -- ---------------------------- DROP TABLE IF EXISTS `user`; CREATE TABLE `user` ( `Id` int(11) NOT NULL AUTO_INCREMENT COMMENT '使用者Id', `username` varchar(30) NOT NULL COMMENT '使用者名稱', `password` varchar(20) NOT NULL COMMENT '密碼', PRIMARY KEY (`Id`) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8; -- ---------------------------- -- Table structure for `user_answer` -- ---------------------------- DROP TABLE IF EXISTS `user_answer`; CREATE TABLE `user_answer` ( `Id` tinyint(10) NOT NULL AUTO_INCREMENT COMMENT '主鍵', `UserId` tinyint(10) NOT NULL COMMENT '使用者id', `TitleId` tinyint(10) DEFAULT NULL COMMENT '題唯一id', `TitleCount` varchar(100) DEFAULT NULL COMMENT '題的數量', `Type` varchar(100) DEFAULT NULL COMMENT '題型別', `TitleA` varchar(100) DEFAULT NULL COMMENT 'A選項', `TitleB` varchar(100) DEFAULT NULL COMMENT 'B選項', `TitleC` varchar(100) DEFAULT NULL COMMENT 'C選項', `TitleD` varchar(100) DEFAULT NULL COMMENT 'D選項', PRIMARY KEY (`Id`) ) ENGINE=InnoDB AUTO_INCREMENT=44 DEFAULT CHARSET=utf8;
系統展示
登陸
註冊
導航欄
系統主頁面
(1)對應使用者建立的問卷,可以進行刪除,編輯和生成問卷的操作
問卷增加介面
(1)操作“點選增加題目條數”按鈕可以增加題目,同理也可以移除
問卷編輯介面
(1)編輯介面可以設定問卷啟用狀態,使得答題連結按鈕是否可以被點亮
(2)啟用狀態的答題連結按鈕被點亮,反之不被點亮
問卷答題介面
(1)可最多包含四種提醒可選,包含Drop down list,Radio button,Checkbox,其中Drop down list有單選和多選兩種選擇,Radio button必為單選,Checkbox必為多選。
問卷資料匯出介面
問卷結果匯出到Excel
(1)點選按鈕
(2)瀏覽器彈出
(3)開啟Excel可看到資料
(4)Crtl+P
列印預覽
前端原始碼之登入註冊
登入介面loginuser.phtml
<!DOCTYPE html>
<!-- http://localhost:443/code/202110/exam/views/loginuser.phtml -->
<html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>登陸</title>
<style>
* {
margin: 0;
padding: 0;
}
html {
height: 100%;
width: 100%;
overflow: hidden;
margin: 0;
padding: 0;
background: url() no-repeat 0px 0px;
background-repeat: no-repeat;
background-size: 100% 100%;
-moz-background-size: 100% 100%;
}
body {
display: flex;
align-items: center;
justify-content: center;
height: 100%;
}a
#loginDiv {
width: 37%;
display: flex;
justify-content: center;
align-items: center;
height: 300px;
background-color: rgba(75, 81, 95, 0.8);
box-shadow: 7px 7px 17px rgba(52, 56, 66, 0.5);
border-radius: 5px;
}
.box {
display: flex;
justify-content: center;
align-items: center;
height: 300px;
width: 400px;
padding: 40px;
background: rgba(0, 0, 0, .8);
box-sizing: border-box;
box-shadow: 0 15px 25px rgba(0, 0, 0, .5);
border-radius: 5px;
}
#name_trip {
margin-left: 50px;
color: red;
}
p {
margin-top: 30px;
margin-left: 20px;
/* color: azure; */
color:white;
}
input {
margin-left: 15px;
border-radius: 5px;
border-style: hidden;
height: 30px;
width: 140px;
background-color: rgba(216, 191, 216, 0.5);
outline: none;
color: #f0edf3;
padding-left: 10px;
}
.button {
border-color: cornsilk;
background-color: rgba(100, 149, 237, .7);
color: aliceblue;
border-style: hidden;
border-radius: 5px;
width: 100px;
height: 31px;
font-size: 16px;
}
</style>
</head>
<body background="./picture/3.jpg" style="background-repeat:repeat; background-attachment: fixed;">
<div class="box">
<form action="./controller/LoginUserController.php" method="post" enctype="multipart/form-data" id='myform' name='myform' class="form-horizontal">
<h1 style="text-align: center;color: white;">登陸</h1>
<p>賬號:<input id="userNname" type="text" name="name" id="name"></p>
<p>密碼: <input id="password" type="password" name="password" id="password"></p>
<div style="text-align: center;margin-top: 30px;">
<input type="submit" class="button" value="登陸" onclick="checkForm();">
<input type="button" class="button" value="註冊" onclick="window.location.href='loginnew.phtml'">
</div>
</form>
</div>
</body>
<script type="text/javascript">
// 初始化
function $(id) {
return document.getElementsById(id);
}
function isEmpty(str){
if(str == null||str.trim()==""){
return true;
}else{
return false;
}
}
function checkForm(){
var name = document.getElementById("name").value;
var password = document.getElementById("password").value;
if(isEmpty(word)){
alert("使用者名稱需要填寫!");
return;
}
if(isEmpty(password)){
alert("密碼需要填寫!");
return;
}
}
</script>
</html>
註冊頁面loginnew.phtml
body主幹部門,其他同登入
<body background="./picture/3.jpg" style="background-repeat:repeat; background-attachment: fixed;">
<div class="box">
<form action="./controller/LoginInController.php" method="post" enctype="multipart/form-data" id='myform' name='myform' class="form-horizontal">
<h1 style="text-align: center;color: white;">註冊</h1>
<p>賬號名稱:<input id="userNname" type="text" name="name" id="name"></p>
<p>密碼輸入:<input id="password" type="password" name="password" id="password"></p>
<p>確認密碼:<input id="password" type="password" name="confirm" id="password"></p>
<div style="text-align: center;margin-top: 30px;">
<input type="submit" class="button" value="註冊" onclick="checkForm();">
<input type="button" class="button" value="返回登入" onclick="window.location.href='loginuser.phtml'">
</div>
</form>
</div>
</body>
系統前端頁面
問卷增加add.phtml
<?
//http://localhost:443/code/202110/exam/views/add.phtml?#
// 問題:複製的表單只能分別提交
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdn.bootcss.com/bootstrap-datetimepicker/4.17.47/css/bootstrap-datetimepicker.min.css" rel="stylesheet">
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js"></script>
<script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="static/js/moment-with-locales.js"></script>
<script src="https://cdn.bootcss.com/bootstrap-datetimepicker/4.17.47/js/bootstrap-datetimepicker.min.js"></script>
<script type="text/javascript" src="./js/jquery.min.js"></script>
<title>ADD QUESTIONNAIRE</title>
</head>
<body>
<?
include './public/top.phtml';
$userId = $_GET["userId"];
?>
<!-- 正文部分start -->
<div class="container mt-3">
<h2><span class="glyphicon glyphicon-plus" aria-hidden="true"></span> 建立問卷</h2>
<p>歡迎使用問卷系統,您可以按照您的需求建立你需要的問卷!!!</p>
<form action="<? echo"./controller/AddController.php?userId=".$userId; ?>" method="post" enctype="multipart/form-data" id='myform' name='myform' class="form-horizontal" target="myIframe">
<table class="table table-bordered" id="Quest_table">
<tbody>
<!-- 題目名稱 -->
<tr>
<th width="15%">
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label"></i>TITLE</label>
</div>
</th>
<td>
<div class="form-group">
<div class="col-sm-10">
<input type="text" class="form-control" id="inputEmail3" placeholder="" name="quest_name">
</div>
</div>
</td>
</tr>
<!-- 題目表述 -->
<tr>
<th width="15%">
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Description</label>
</div>
</th>
<td>
<div class="form-group">
<div class="col-sm-10">
<input type="text" class="form-control" id="inputEmail3" placeholder="" name="quest_description" >
</div>
</div>
</td>
</tr>
<!-- 選擇截至時間 -->
<tr style="display: none;">
<th width="15%">
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">EndTime</label>
</div>
</th>
<td>
<div class="form-group">
<div class="col-sm-10">
<input type="date" id="date" name = "" value="">
</div>
</div>
</td>
</tr>
<!-- 題目增加 -->
<tr>
<th width="15%">
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Add/Remove</label>
</div>
</th>
<td>
<div class="form-group">
<div class="col-sm-10">
<input class="btn btn-default" type="button" value="點選增加題目條數" id="AddOne">
</div>
</div>
<div class="form-group">
<div class="col-sm-10">
<input class="btn btn-default" type="button" value="點選減少題目條數" id="RemoveOne">
</div>
</div>
</td>
</tr>
<!-- 題目選擇 -->
<tr id="a">
<th width="15%">
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Edit</label>
</div>
</th>
<td>
<div class="form-group">
<div class="col-sm-10">
<p><span class="glyphicon glyphicon-align-left" aria-hidden="true"></span>問題序號:<input type="text" class="form-control" id="inputEmail3" placeholder="" name="<? echo "title_count[]";?>"></p>
<p><span class="glyphicon glyphicon-align-left" aria-hidden="true"></span>問題標題:<input type="text" class="form-control" id="inputEmail3" placeholder="" name="<? echo "title_title[]";?>"></p>
<p><span class="glyphicon glyphicon-wrench" aria-hidden="true">問題型別:
<select class="form-control" id="type" name="<? echo "type[]";?>">
<option value="1">Single_choice Drop_down_list</option>
<option value="2">Multiple_choic Drop_down_list</option>
<option value="3">Single_choice Radio_button</option>
<option value="4">Multiple_choic Checkbox_button</option>
</select>
</p>
<p><span class="glyphicon glyphicon-align-left" aria-hidden="true"></span>選項1:<input type="text" class="form-control" id="inputEmail3" placeholder="" name="<? echo "title_a[]";?>"></p>
<p><span class="glyphicon glyphicon-align-left" aria-hidden="true"></span>選項2:<input type="text" class="form-control" id="inputEmail3" placeholder="" name="<? echo "title_b[]";?>"></p>
<p><span class="glyphicon glyphicon-align-left" aria-hidden="true"></span>選項3:<input type="text" class="form-control" id="inputEmail3" placeholder="" name="<? echo "title_c[]";?>"></p>
<p><span class="glyphicon glyphicon-align-left" aria-hidden="true"></span>選項4:<input type="text" class="form-control" id="inputEmail3" placeholder="" name="<? echo "title_d[]";?>"></p>
<br>
</div>
</div>
</td>
</tr>
</tbody>
<tfoot>
<tr>
<th>Operation</th>
<!-- 表單提交 -->
<td>
<input class="btn btn-default" type="submit" value="提交" id="SubmitData">
<input class="btn btn-default" type="button" value="返回" onclick="history.go(-1)">
</td>
</tr>
</tfoot>
</tbody>
</table>
</form>
<iframe id="myIframe" name="myIframe" class="iframes" style="display: none;"></iframe>
</body>
<script type="text/javascript">
// 增加題目條數
$(document).ready(function(){
$("#AddOne").click(function(){
var tr = $("#Quest_table tr").eq(4).clone();
tr.appendTo("#Quest_table tbody");
});
});
$(document).ready(function(){
$("#RemoveOne").click(function(){
var length = $("#Quest_table tbody tr").length;
if(length==5){
alert("每個問卷必須保證至少一道題目!");
}
if(length>5){
$('#Quest_table tbody tr:last').remove();
}
});
});
</script>
</html>
除此之外,在移除題目條數的時候也可以這麼寫
<script type="text/javascript">
$(document).ready(function(){
$("#RemoveOne").click(function(){
var length = $("#Quest_table tbody tr").length;
if(length==5){
alert("每個問卷必須保證至少一道題目!!!");
}
if(length>5){
$("#Quest_table tbody tr").eq(length-1).remove();
}
});
});
</script>
問卷編輯介面edit.phtml
<?
include './controller/HomeServics.php';
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdn.bootcss.com/bootstrap-datetimepicker/4.17.47/css/bootstrap-datetimepicker.min.css" rel="stylesheet">
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js"></script>
<script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="static/js/moment-with-locales.js"></script>
<script src="https://cdn.bootcss.com/bootstrap-datetimepicker/4.17.47/js/bootstrap-datetimepicker.min.js"></script>
<script type="text/javascript" src="./js/jquery.min.js"></script>
<title>EDIT QUESTIONNAIRE</title>
</head>
<body>
<?
include './public/top.phtml';
$titleid = $_GET["titleid"];
$userId = $_GET["userId"];
$homeControllerObj = new HomeController();
//標題名字
$questName = $homeControllerObj->getQuestName($titleid);
//標題描述
$questDescription = $homeControllerObj->getQuestDescription($titleid);
//具體資料
$returnData = $homeControllerObj->getAllData($titleid);
//題目數量
$returnCount = $homeControllerObj->getAllDataCount($titleid);
//當前的啟用狀態
$active = $homeControllerObj->getActiveStatus($titleid);
//var_dump($active); string(1) "1"
?>
<div class="container mt-3">
<!-- 樣例 -->
<h2><span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> 問卷編輯</h2>
<p>歡迎使用問卷系統,按照您的需求可以進行問卷編輯!!!</p>
<form action="<? echo"./controller/EditController.php?userId=".$userId."&&titleid=".$titleid; ?>" method="post" enctype="multipart/form-data" id='myform' name='myform' class="form-horizontal" target="myIframe">
<table class="table table-bordered">
<tr>
<th width="10%">
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label"></i>TITLE</label>
</div>
</th>
<td>
<div class="form-group">
<div class="col-sm-10">
<input type="text" class="form-control" id="inputEmail3" placeholder="" name="quest_name" value="<? echo $questName; ?>">
</div>
</div>
</td>
</tr>
<tr>
<th width="10%">
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label"></i>Description</label>
</div>
</th>
<td>
<div class="form-group">
<div class="col-sm-10">
<input type="text" class="form-control" id="inputEmail3" placeholder="" name="quest_description" value="<? echo $questDescription; ?>">
</div>
</div>
</td>
</tr>
<tr>
<th width="10%">
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label"></i>Active Status</label>
</div>
</th>
<td>
<?
if($active == "1"){
?>
<label class="radio-inline">
<input type="radio" name="Active" id="inlineRadio1" value="1" checked> 已啟用
</label>
<label class="radio-inline">
<input type="radio" name="Active" id="inlineRadio2" value="0"> 未啟用
</label>
<?
}else{
?>
<label class="radio-inline">
<input type="radio" name="Active" id="inlineRadio1" value="1"> 已啟用
</label>
<label class="radio-inline">
<input type="radio" name="Active" id="inlineRadio2" value="0" checked> 未啟用
</label>
<?
}
?>
</td>
</tr>
<?php
for($i=0;$i<$returnCount;$i++){
$tiNumber = $returnData[$i] ["TitleCount"];
echo "<tr>";
echo "<th>";
echo "問題".$tiNumber;
echo "</th>";
echo "<td>";
if($returnData[$i]["Type"] == "1"){//單選題
?>
<p><span class="glyphicon glyphicon-wrench" aria-hidden="true">問題型別:
<select class="form-control" id="type" name="<? echo "type_".$tiNumber; ?>">
<option value="1" checked>Single_choice Drop_down_list</option>
<option value="2">Multiple_choic Drop_down_list</option>
<option value="3">Single_choice Radio_button</option>
<option value="4">Multiple_choic Checkbox_button</option>
</select>
<? }//單選select結束
if($returnData[$i]["Type"] == "2"){
?>
<p><span class="glyphicon glyphicon-wrench" aria-hidden="true">問題型別:
<select class="form-control" id="type" name="<? echo "type_".$tiNumber; ?>">
<option value="2" checked>Multiple_choic Drop_down_list</option>
<option value="1">Single_choice Drop_down_list</option>
<option value="3">Single_choice Radio_button</option>
<option value="4">Multiple_choic Checkbox_button</option>
</select>
<?
}//多選select結束
if($returnData[$i]["Type"] == "3"){//radio
?>
<p><span class="glyphicon glyphicon-wrench" aria-hidden="true">問題型別:
<select class="form-control" id="type" name="<? echo "type_".$tiNumber; ?>">
<option value="3" checked>Single_choice Radio_button</option>
<option value="1">Single_choice Drop_down_list</option>
<option value="2">Multiple_choic Drop_down_list</option>
<option value="4">Multiple_choic Checkbox_button</option>
</select>
<?
}//radio迴圈end
if($returnData[$i]["Type"] == "4"){//checkbox
?>
<p><span class="glyphicon glyphicon-wrench" aria-hidden="true">問題型別:
<select class="form-control" id="type" name="<? echo "type_".$tiNumber; ?>">
<option value="4" checked>Multiple_choic Checkbox_button</option>
<option value="1">Single_choice Drop_down_list</option>
<option value="2">Multiple_choic Drop_down_list</option>
<option value="3">Single_choice Radio_button</option>
</select>
<?
}//checkbox迴圈end
?>
<!-- <p><span class="glyphicon glyphicon-align-left" aria-hidden="true"></span>問題序號:
<input type="text" class="form-control" id="inputEmail3" value="" name=""></p> -->
<p><span class="glyphicon glyphicon-align-left" aria-hidden="true"></span>問題標題:
<input type="text" class="form-control" id="inputEmail3" value="<? echo $returnData[$i]["TitleTitle"];?>" name="<?echo "tiltle_".$tiNumber;?>"></p>
<p><span class="glyphicon glyphicon-align-left" aria-hidden="true"></span>選項1:
<input type="text" class="form-control" id="inputEmail3" value="<? echo $returnData[$i]["TitleA"];?>" name="<?echo "a_".$tiNumber;?>"></p>
<p><span class="glyphicon glyphicon-align-left" aria-hidden="true"></span>選項2:
<input type="text" class="form-control" id="inputEmail3" value="<? echo $returnData[$i]["TitleB"];?>" name="<?echo "b_".$tiNumber;?>"></p>
<p><span class="glyphicon glyphicon-align-left" aria-hidden="true"></span>選項3:
<input type="text" class="form-control" id="inputEmail3" value="<? echo $returnData[$i]["TitleC"];?>" name="<?echo "c_".$tiNumber;?>"></p>
<p><span class="glyphicon glyphicon-align-left" aria-hidden="true"></span>選項4:
<input type="text" class="form-control" id="inputEmail3" value="<? echo $returnData[$i]["TitleD"];?>" name="<?echo "d_".$tiNumber;?>"></p>
</td>
<?php
}
echo "</tr>";
?>
<tr>
<th width="10%">
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label"></i>Operate</label>
</div>
</th>
<td>
<input class="btn btn-default" type="submit" value="提交" id="SubmitData">
</td>
</tr>
</table>
</form>
<iframe id="myIframe" name="myIframe" class="iframes" style="display: none;"></iframe>
</div>
</body>
</html>
問卷生成介面public.phtml
<?
include './controller/HomeServics.php';
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<script type="text/javascript" src="./js/jquery.min.js"></script>
<title>PUBLIC QUESTIONNAIRE</title>
</head>
<body>
<?
include './public/top.phtml';
?>
<!-- 正文開始 -->
<div class="container mt-3">
<!-- 樣例 -->
<h2><span class="glyphicon glyphicon-ok" aria-hidden="true"></span> 問卷展示</h2>
<p>歡迎使用問卷系統,按照您的需求已經生成問卷!!!</p>
<table class="table table-bordered">
<tr>
<th width="10%">
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label"></i>TITLE</label>
</div>
</th>
<td>
<?
$titleid = $_GET["titleid"];
$homeControllerObj = new HomeController();
$questName = $homeControllerObj->getQuestName($titleid);
echo $questName;
?>
</td>
</tr>
<tr>
<th>
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Description</label>
</div>
</th>
<td>
<?
$questDescription = $homeControllerObj->getQuestDescription($titleid);
echo $questDescription;
?>
</td>
</tr>
<?
$returnData = $homeControllerObj->getAllData($titleid);
$returnCount = $homeControllerObj->getAllDataCount($titleid);
for($i=0;$i<$returnCount;$i++){
if($returnData[$i]["Type"] == "1"){
//單選題
echo "<tr>";echo "<th>";
echo "問題".$returnData[$i] ["TitleCount"];
echo "</th>";echo "<td>";
?>
<p><span class="glyphicon glyphicon-align-left" aria-hidden="true"></span><? echo "問題標題:".$returnData[$i]["TitleTitle"]; ?></p>
<!-- 寫選項 -->
<select class="form-control" id="type" name="type">
<option value="1"><? echo $returnData[$i]["TitleA"]; ?></option>
<option value="2"><? echo $returnData[$i]["TitleB"]; ?></option>
<option value="3"><? echo $returnData[$i]["TitleC"]; ?></option>
<option value="4"><? echo $returnData[$i]["TitleD"]; ?></option>
</select>
<?
echo "</td>";
echo "</tr>";
}//if迴圈結束
//多選題
if($returnData[$i]["Type"] == "2"){
echo "<tr>";echo "<th>";
echo "問題".$returnData[$i] ["TitleCount"];
echo "</th>";echo "<td>";
?>
<p><span class="glyphicon glyphicon-align-left" aria-hidden="true"></span><? echo "問題標題:".$returnData[$i]["TitleTitle"]; ?></p>
<select multiple class="form-control" id="type" name="type">
<option value="1"><? echo $returnData[$i]["TitleA"]; ?></option>
<option value="2"><? echo $returnData[$i]["TitleB"]; ?></option>
<option value="3"><? echo $returnData[$i]["TitleC"]; ?></option>
<option value="4"><? echo $returnData[$i]["TitleD"]; ?></option>
</select>
<?
}//if多選迴圈
if($returnData[$i]["Type"] == "3"){//Radio button
echo "<tr>";echo "<th>";
echo "問題".$returnData[$i] ["TitleCount"];
echo "</th>";echo "<td>";
?>
<p><span class="glyphicon glyphicon-align-left" aria-hidden="true"></span><? echo "問題標題:".$returnData[$i]["TitleTitle"]; ?></p>
<div class="radio">
<label>
<input type="radio" name="<?echo "radio_".$returnData[$i]["TitleCount"];?>" id="optionsRadios1" value="1" checked>
<? echo $returnData[$i]["TitleA"]; ?>
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="<?echo "radio_".$returnData[$i]["TitleCount"];?>" id="optionsRadios1" value="1" >
<? echo $returnData[$i]["TitleB"]; ?>
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="<?echo "radio_".$returnData[$i]["TitleCount"];?>" id="optionsRadios1" value="1" >
<? echo $returnData[$i]["TitleC"]; ?>
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="<?echo "radio_".$returnData[$i]["TitleCount"];?>" id="optionsRadios1" value="1" >
<? echo $returnData[$i]["TitleD"]; ?>
</label>
</div>
<?
}//Radio button迴圈結束
if($returnData[$i]["Type"] == "4"){//Checkbox題型
echo "<tr>";echo "<th>";
echo "問題".$returnData[$i] ["TitleCount"];
echo "</th>";echo "<td>";
?>
<p><span class="glyphicon glyphicon-align-left" aria-hidden="true"></span><? echo "問題標題:".$returnData[$i]["TitleTitle"]; ?></p>
<input type="checkbox" value="" name="<?echo "checkbox_".$returnData[$i]["TitleCount"];?>"><? echo $returnData[$i]["TitleA"]; ?>
<input type="checkbox" value="" name="<?echo "checkbox_".$returnData[$i]["TitleCount"];?>"><? echo $returnData[$i]["TitleB"]; ?>
<input type="checkbox" value="" name="<?echo "chexkbox_".$returnData[$i]["TitleCount"];?>"> <? echo $returnData[$i]["TitleC"]; ?>
<input type="checkbox" value="" name="<?echo "checkbox_".$returnData[$i]["TitleCount"];?>"><? echo $returnData[$i]["TitleD"]; ?>
<?
}//Checkbox題型迴圈結束
}//最終迴圈
?>
</table>
</select>
</div>
</body>
</html>
問卷作答頁面answer.phtml
<?
include './controller/HomeServics.php';
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<script type="text/javascript" src="./js/jquery.min.js"></script>
<title>PUBLIC QUESTIONNAIRE</title>
</head>
<body>
<?
include './public/top.phtml';
$param = $_GET["titleid"];
$userId = $_GET["userId"];
?>
<!-- 正文開始 -->
<div class="container mt-3">
<!-- 樣例 -->
<h2><span class="glyphicon glyphicon-ok" aria-hidden="true"></span> 問卷作答</h2>
<p>歡迎使用問卷系統,按照您的需求已經生成問卷!!!</p>
<form action="<? echo "./controller/AnswerController.php?titleid=".$param."&&userId=".$userId; ?>" method="post" enctype="multipart/form-data" id='myform' name='myform' class="form-horizontal" target="myIframe">
<table class="table table-bordered">
<tr>
<th width="10%">
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label"></i>TITLE</label>
</div>
</th>
<td>
<?
//var_dump($_GET["titleid"]);
$titleid = $_GET["titleid"];
$homeControllerObj = new HomeController();
$questName = $homeControllerObj->getQuestName($titleid);
echo $questName;
?>
</td>
</tr>
<tr>
<th>
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Description</label>
</div>
</th>
<td>
<?
$questDescription = $homeControllerObj->getQuestDescription($titleid);
echo $questDescription;
?>
</td>
</tr>
<?
$returnData = $homeControllerObj->getAllData($titleid);
$returnCount = $homeControllerObj->getAllDataCount($titleid);
for($i=0;$i<$returnCount;$i++){
if($returnData[$i]["Type"] == "1"){
//單選題
echo "<tr>";
echo "<th>";
echo "問題".$returnData[$i] ["TitleCount"];
echo "</th>";
echo "<td>";
$valueName = $returnData[$i]["TitleCount"];
?>
<p><span class="glyphicon glyphicon-align-left" aria-hidden="true"></span><? echo "單選題--問題標題:".$returnData[$i]["TitleTitle"]; ?></p>
<!-- 寫選項 -->
<select class="form-control" id="type" name="<? echo "dan_".$valueName; ?>">
<option value="1"><? echo $returnData[$i]["TitleA"]; ?></option>
<option value="2"><? echo $returnData[$i]["TitleB"]; ?></option>
<option value="3"><? echo $returnData[$i]["TitleC"]; ?></option>
<option value="4"><? echo $returnData[$i]["TitleD"]; ?></option>
</select>
<?
echo "</td>";
echo "</tr>";
}//if迴圈結束
//多選題
if($returnData[$i]["Type"] == "2"){
echo "<tr>";
echo "<th>";
echo "問題".$returnData[$i] ["TitleCount"];
echo "</th>";
echo "<td>";
$valueName = $returnData[$i]["TitleCount"];
?>
<p><span class="glyphicon glyphicon-align-left" aria-hidden="true"></span><? echo "多選題--問題標題:".$returnData[$i]["TitleTitle"]; ?></p>
<select multiple class="form-control" id="type" name="<? echo "duo_".$valueName."[]"; ?>">
<option value="1"><? echo $returnData[$i]["TitleA"]; ?></option>
<option value="2"><? echo $returnData[$i]["TitleB"]; ?></option>
<option value="3"><? echo $returnData[$i]["TitleC"]; ?></option>
<option value="4"><? echo $returnData[$i]["TitleD"]; ?></option>
</select>
<?
echo "</td>";
echo "</tr>";
}//if多選迴圈
if($returnData[$i]["Type"] == "3"){
echo "<tr>";
echo "<th>";
echo "問題".$returnData[$i] ["TitleCount"];
echo "</th>";
echo "<td>";
$valueName = $returnData[$i]["TitleCount"];//題號
?>
<p><span class="glyphicon glyphicon-align-left" aria-hidden="true"></span><? echo "單選Radio--問題標題:".$returnData[$i]["TitleTitle"]; ?></p>
<div class="radio">
<label>
<input type="radio" name="<?echo "radio_".$valueName;?>" id="optionsRadios1" value="1" checked>
<? echo $returnData[$i]["TitleA"]; ?>
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="<?echo "radio_".$valueName;?>" id="optionsRadios1" value="2" >
<? echo $returnData[$i]["TitleB"]; ?>
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="<?echo "radio_".$valueName;?>" id="optionsRadios1" value="3" >
<? echo $returnData[$i]["TitleC"]; ?>
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="<?echo "radio_".$valueName;?>" id="optionsRadios1" value="4" >
<? echo $returnData[$i]["TitleD"]; ?>
</label>
</div>
<? echo "</td>";
echo "</tr>";
}//if_radio_單選迴圈
if($returnData[$i]["Type"] == "4"){//Checkbox
echo "<tr>";
echo "<th>";
echo "問題".$returnData[$i] ["TitleCount"];
echo "</th>";
echo "<td>";
$valueName = $returnData[$i]["TitleCount"];//題號
?>
<p><span class="glyphicon glyphicon-align-left" aria-hidden="true"></span><? echo "多選Checkbox--問題標題:".$returnData[$i]["TitleTitle"]; ?></p>
<div>
<input type="checkbox" value="1" name="<?echo "chexkbox_".$valueName."[]";?>">
<? echo $returnData[$i]["TitleA"]; ?>
<input type="checkbox" value="2" name="<?echo "chexkbox_".$valueName."[]";?>">
<? echo $returnData[$i]["TitleB"]; ?>
<input type="checkbox" value="3" name="<?echo "chexkbox_".$valueName."[]";?>">
<? echo $returnData[$i]["TitleC"]; ?>
<input type="checkbox" value="4" name="<?echo "chexkbox_".$valueName."[]";?>">
<? echo $returnData[$i]["TitleD"]; ?>
</div>
<?
echo "</td>";
echo "</tr>";
}//Checkbox迴圈結束
}//最終迴圈
?>
<tr>
<th>
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Operation</label>
</div>
</th>
<td>
<input class="btn btn-default" type="submit" value="提交" id="SubmitData">
<input class="btn btn-default" type="button" value="返回" onclick="history.go(-1)">
</td>
</tr>
</table>
<iframe id="myIframe" name="myIframe" class="iframes" style="display:none"></iframe>
</form>
</div>
</body>
<script>
$(document).ready(function(){
$("#SubmitData").click(function(){
alert("您已作答成功,感謝參與");
});
});
</script>
</html>
網頁作答情況展示介面webexport.phtml
<?
include './controller/HomeServics.php';
$titleid = $_GET["titleid"];
$homeControllerObj = new HomeController();
//獲取所有答題人的Id
$userIdArray = $homeControllerObj->getAllUserId($titleid);
//獲取答題人的數目
$userIdCount = $homeControllerObj->getCountUserid($titleid);
//獲取原題資訊
$QuestArray = $homeControllerObj->getAllData($titleid);
//獲取題目的數目
$QuestCount = $homeControllerObj->getAllDataCount($titleid);
//獲取總題目
$QuestName = $homeControllerObj->getQuestName($titleid);
//標題描述
$QuestDescription = $homeControllerObj->getQuestDescription($titleid);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdn.bootcss.com/bootstrap-datetimepicker/4.17.47/css/bootstrap-datetimepicker.min.css" rel="stylesheet">
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js"></script>
<script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="static/js/moment-with-locales.js"></script>
<script src="https://cdn.bootcss.com/bootstrap-datetimepicker/4.17.47/js/bootstrap-datetimepicker.min.js"></script>
<script type="text/javascript" src="./js/jquery.min.js"></script>
<title>Web Data Output Display</title>
<style>
@media print {
@import url("my-print-style.css") print;
.noprint {
display: none
}
body {
background-color: white;
}
img {
visibility: hidden;
}
/* 所有連結後顯示連結地址 */
a::after {
content: "(" attr(href) ")";
}
}
</style>
</head>
<body>
<?
include './public/top.phtml';
?>
<div class="container mt-3">
<div class="noprint">
<h2><span class="glyphicon glyphicon-zoom-out" aria-hidden="true"></span> 資訊查詢</h2>
<code>溫馨提示,Crtl+P快捷鍵可列印</code>
<p>歡迎使用問卷系統,您可以在網頁檢視作答資訊!!!也可以點選右側按鈕進行下載。
<span class="glyphicon glyphicon-hand-right" aria-hidden="true">
<span class="glyphicon glyphicon-hand-right" aria-hidden="true">
<span class="glyphicon glyphicon-hand-right" aria-hidden="true">
<a href ="<?echo "./controller/ExcelController.php?titleid=".$titleid;?>" class="btn btn-default active"><span class="glyphicon glyphicon-circle-arrow-down" aria-hidden="true"></span></a></p>
</div>
<table class="table table-bordered">
<tr>
<th width="20%">
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label"></i>TITLE</label>
</div>
</th>
<td>
<?echo $QuestName;?>
</td>
</tr>
<tr>
<th width="20%">
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label"></i>Description</label>
</div>
</th>
<td>
<?echo $QuestDescription;?>
</td>
</tr>
<?
for($i=0;$i<$userIdCount;$i++){
echo "<tr>";
$userId = $userIdArray[$i]["UserId"];
$username = $homeControllerObj->getUserNameById($userId);
echo "<th>"."使用者名稱"."</th>";
echo "<th>".$username."</th>";
echo "</tr>";
for($j=0;$j<$QuestCount;$j++){
$titleCount = $QuestArray[$j]["TitleCount"];
$smalltitle = $QuestArray[$j]["TitleTitle"];
echo "<th>"."問題序號:"."</th>";
if($QuestArray[$j]["Type"]=="1"){//單選
echo "<td>"."Select.單選——".$titleCount.":".$smalltitle."</td>";
}
if($QuestArray[$j]["Type"]=="2"){//多
echo "<td>"."Select.多選——".$titleCount.":".$smalltitle."</td>";
}
if($QuestArray[$j]["Type"]=="3"){//radio
echo "<td>"."Radio——".$titleCount.":".$smalltitle."</td>";
}
if($QuestArray[$j]["Type"]=="4"){//checkbox
echo "<td>"."Checkbox——".$titleCount.":".$smalltitle."</td>";
}
echo "<td>"."A選項:".$QuestArray[$j]["TitleA"]."</td>";
echo "<td>"."B選項:".$QuestArray[$j]["TitleB"]."</td>";
echo "<td>"."C選項:".$QuestArray[$j]["TitleC"]."</td>";
echo "<td>"."D選項:".$QuestArray[$j]["TitleD"]."</td>";
$OpertionArray = $homeControllerObj->getOpertionData($titleid,$titleCount,$userId);
$arraycount = count($OpertionArray);
for($k=0;$k<$arraycount;$k++){
echo "<tr>";
echo "<th>".""."</th>";
echo "<th>".""."</th>";
if($OpertionArray[$k]["TitleA"]!=null){?>
<td><span class="glyphicon glyphicon-ok" aria-hidden="true"></span></td>
<? echo "<td>".""."</td>";
echo "<td>".""."</td>";
echo "<td>".""."</td>";
}
if($OpertionArray[$k]["TitleB"]!=null){
echo "<td>".""."</td>";?>
<td><span class="glyphicon glyphicon-ok" aria-hidden="true"></span></td>
<? echo "<td>".""."</td>";
echo "<td>".""."</td>";
}
if($OpertionArray[$k]["TitleC"]!=null){
echo "<td>".""."</td>";
echo "<td>".""."</td>";?>
<td><span class="glyphicon glyphicon-ok" aria-hidden="true"></span></td>
<? echo "<td>".""."</td>";
}
if($OpertionArray[$k]["TitleD"]!=null){
echo "<td>".""."</td>";
echo "<td>".""."</td>";
echo "<td>".""."</td>";?>
<td><span class="glyphicon glyphicon-ok" aria-hidden="true"></span></td>
<? }
echo "</tr>";
}
}
}
?>
</table>
</div>
</body>
</html>
系統主頁面home.phtml
<?
include './controller/QuestDao.php';
include './controller/UserDao.php';
$userId=$_GET["userId"];
$userDaoObj = new userDao();
$username = $userDaoObj->getUserNameById($userId);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<script type="text/javascript" src="./js/jquery.min.js"></script>
<title>PUBLIC QUESTIONNAIRE</title>
<style type="text/css"></style>
</head>
<body>
<? include './public/top.phtml'; ?>
<!-- 正文開始 -->
<div class="container mt-3">
<!-- 樣例 -->
<h2><span class="glyphicon glyphicon-globe" aria-hidden="true"></span> 您好,歡迎<?echo $username;?>來到系統主頁面</h2>
<!-- <p></p> -->
<table class="table table-bordered table-hover">
<tr>
<th width="15%">
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Quest Number</label>
</th>
<th>
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Quest Creator</label>
</div>
</th>
<th>
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Quest Name</label>
</div>
</th>
<th>
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Active Status</label>
</div>
</th>
<th>
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Your Operation</label>
</div>
</th>
<th>
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Data Output</label>
</div>
</th>
</tr>
<?
$flag=1;
$questDaoObj = new questDao();
$resultArray = $questDaoObj->findDataTitleId();
$resultCount = $questDaoObj->findCountTitleId();
for ($i=0;$i<$resultCount;$i++){
$param = $resultArray[$i]["TitleId"];
$creatorid = $resultArray[$i]["CreatBy"];
$creator = $userDaoObj->getUserNameById($creatorid);
$tempName = $questDaoObj->getQuestName($param);
$active = $questDaoObj->findActive($param);
echo "<tr>";
echo "<td>".$flag."</td>";
echo "<td>".$creator."</td>";
echo "<td>".$tempName."</td>";
if($active == "1"){
echo "<td>"."問卷已啟用"."</td>";
}else{
echo "<td>"."問卷未啟用"."</td>";
}
echo "<td>";
if($resultArray[$i]["CreatBy"]==$userId){
?>
<a href ="<? echo"./controller/DeleteController.php?titleid=".$param;?>" class="btn btn-default active"><span class="glyphicon glyphicon-trash" aria-hidden="true"></span>刪除</a>
<a href ="<? echo "edit.phtml?titleid=".$param."&&userId=".$userId;?>" class="btn btn-default active"><span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>編輯</a>
<a href ="<? echo "public.phtml?titleid=".$param."&&userId=".$userId; ?>" class="btn btn-default active"><span class="glyphicon glyphicon-file" aria-hidden="true"></span>生成問卷</a>
<?
if($active == "1"){
?>
<a href ="<? echo "answer.phtml?titleid=".$param."&&userId=".$userId;?>" class="btn btn-default active"><span class="glyphicon glyphicon-edit" aria-hidden="true"></span>答題連結</a>
<?
}else{
?>
<a href ="<? echo "answer.phtml?titleid=".$param."&&userId=".$userId;?>" class="btn btn-default disabled"><span class="glyphicon glyphicon-edit" aria-hidden="true"></span>答題連結</a>
<?
}
}else{?>
<a href ="<? echo"./controller/DeleteController.php?titleid=".$param;?>" class="btn btn-default disabled"><span class="glyphicon glyphicon-trash" aria-hidden="true"></span>刪除</a>
<a href ="<? echo "edit.phtml?titleid=".$param."&&userId=".$userId;?>" class="btn btn-default disabled" ><span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>編輯</a>
<a href ="<? echo "public.phtml?titleid=".$param."&&userId=".$userId; ?>" class="btn btn-default disabled"><span class="glyphicon glyphicon-file" aria-hidden="true"></span>生成問卷</a>
<?
if($active == "1"){
?>
<a href ="<? echo "answer.phtml?titleid=".$param."&&userId=".$userId;?>" class="btn btn-default active"><span class="glyphicon glyphicon-edit" aria-hidden="true"></span>答題連結</a>
<?
}else{
?>
<a href ="<? echo "answer.phtml?titleid=".$param."&&userId=".$userId;?>" class="btn btn-default disabled"><span class="glyphicon glyphicon-edit" aria-hidden="true"></span>答題連結</a>
<?
}
}
echo "</td>";
?><td><a href ="<? echo"webexport.phtml?titleid=".$param."&&userId=".$userId;?>" class="btn btn-default active"><span class="glyphicon glyphicon-zoom-out" aria-hidden="true"></span>資料匯出</a></td><?
$flag++;
}
echo "</tr>";
?>
</div>
</body>
</html>
其他前端樣式
標題public>top.phtml
<!-- 導航欄部分start -->
<?
$userId=$_GET["userId"];
?>
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#"><span class="glyphicon glyphicon-home" aria-hidden="true"></span> 問卷系統</a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li><a href="<?echo "../views/home.phtml?userId=".$userId; ?>">Home<span class="sr-only">(current)</span></a></li>
<li><a href="<?echo "./add.phtml?userId=".$userId; ?>">Add Quest</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><a href="./loginuser.phtml"><span class="glyphicon glyphicon-off" aria-hidden="true"></span>登出賬號</a></li>
</ul>
</div>
</div>
</nav>
登入註冊後端
登入LoginUserController.php
<?php
include 'UserDao.php';
$name = $_POST["name"];
$password = $_POST["password"];
if($name==null){
echo"<script type='text/javascript'>alert('帳號名不能為空');</script>";
return;
}
if($password == null){
echo"<script type='text/javascript'>alert('密碼不能為空');</script>";
return;
}
$userDaoObj = new userDao();
$records = $userDaoObj->getMessage($name,$password);
if($records!=0){
$userId = $userDaoObj->getUserId($name,$password);
echo"<script type='text/javascript'>alert('登陸成功');</script>";
Header("Location: ../home.phtml?userId={$userId}");
}else{
Header("Location: ../loginuser.phtml");
}
註冊LoginInController.php
<?
include 'UserDao.php';
var_dump($_POST);
if($_POST["name"] == null){
echo"<script type='text/javascript'>alert('帳號名不能為空');</script>";
return;
}
if($_POST["password"] == null){
echo"<script type='text/javascript'>alert('密碼不能為空');</script>";
return;
}
if($_POST["confirm"] == null){
echo"<script type='text/javascript'>alert('密碼確認不能為空');</script>";
return;
}
if($_POST["confirm"]!=$_POST["password"]&&$_POST["password"]!=null&&$_POST["confirm"] !=null){
echo"<script type='text/javascript'>alert('兩次密碼不一致');</script>";
}
$name = $_POST["name"];
$password = $_POST["password"];
$confirm = $_POST["confirm"];
$userDaoObj = new userDao();
if($password == $confirm && $password!=null && $confirm!=null){
$userDaoObj->insertData($name,$password);
Header("Location: ../loginuser.phtml");
}
後端程式碼
問卷增加AddController.php
<?
include './QuestDao.php';
$creatby = $_GET["userId"];
$count = count($_POST["type"]);
$QuestName = $_POST["quest_name"];
$QuestDescription = $_POST["quest_description"];
$questDao = new questDao();
for($i=0;$i<$count;$i++){
$TitleCount = $_POST["title_count"][$i];
$TitleTitle = $_POST["title_title"][$i];
$Type = $_POST["type"][$i];
$TitleA = $_POST["title_a"][$i];
$TitleB = $_POST["title_b"][$i];
$TitleC = $_POST["title_c"][$i];
$TitleD = $_POST["title_d"][$i];
$creatby = $_GET["userId"];
$result = $questDao->insertDate($QuestName,$QuestDescription,$TitleCount,$TitleTitle,$Type,$TitleA,$TitleB,$TitleC,$TitleD,$creatby);
}
echo"<script type='text/javascript'>alert('題目提交成功');</script>";
問卷編輯EditController.php
<?php
include 'HomeServics.php';
$TitleId = $_GET["titleid"];
$CreatBy = $_GET["userId"];
$active = (int)($_POST["Active"]);
$homeControllerObj = new HomeController();
$homeControllerObj->updateActive($active,$TitleId);
//之前的資料
$returnData = $homeControllerObj->getAllData($TitleId);
//題目數量
$returnCount = $homeControllerObj->getAllDataCount($TitleId);
echo $returnCount;
$QuestName = $_POST["quest_name"]; //題目
$QuestDescription = $_POST["quest_description"]; //題目描述
echo $QuestName;
echo $QuestDescription;
for($i=0;$i<$returnCount;$i++){
$tiNumber = $returnData[$i]["TitleCount"];
$type = "type_".$tiNumber;//問題型別
$typeValue = $_POST[$type];
$titleTitle = "tiltle_".$tiNumber;//問題標題
$titleTitleValue = $_POST[$titleTitle];
$a = "a_".$tiNumber; //第1個選項
$aValue = $_POST[$a];
$b = "b_".$tiNumber; //第2個選項
$bValue = $_POST[$b];
$c = "c_".$tiNumber; //第3個選項
$cValue = $_POST[$c];
$d = "d_".$tiNumber; //第4個選項
$dValue = $_POST[$d];
$homeControllerObj->update($QuestName,$QuestDescription,$tiNumber,$titleTitleValue,$typeValue,$aValue,$bValue,$cValue,$dValue,$TitleId);
}
echo"<script type='text/javascript'>alert('題目更改成功');</script>";
問卷刪除DeleteController.php
<?php
include 'HomeServics.php';
$titleid = $_GET["titleid"];
$homeControllerObj = new HomeController();
$homeControllerObj->delete($titleid);
$homeControllerObj->delectDataByTitleid($titleid);
echo"<script type='text/javascript'>alert('題目刪除成功');</script>";
問卷作答AnswerController.php
<?php
include 'HomeServics.php';
$titleid = $_GET["titleid"];
$userId = $_GET["userId"];
$homeControllerObj = new HomeController();
$returnData = $homeControllerObj->getAllData($titleid);
$returnCount = $homeControllerObj->getAllDataCount($titleid);
for($i=0;$i<$returnCount;$i++){
$type = $returnData[$i]["Type"];
if($type == "1"){
//此題是單選
$valueName = $returnData[$i]["TitleCount"];//題號
$param = "dan_".$valueName;
$change = $_POST[$param];//選的是哪個選項,即ABCD
$homeControllerObj->radioInset($titleid,$userId,$valueName,$type,$change);
}
if($type == "2"){
//此題是多選
$valueName = $returnData[$i]["TitleCount"];
$param = "duo_".$valueName;
$duoArray = $_POST[$param];
$arrayCount = sizeof($duoArray);//計算陣列長度
for($j=0;$j<$arrayCount;$j++){
$change = $duoArray[$j];
$homeControllerObj->radioInset($titleid,$userId,$valueName,$type,$change);
}
}
if($type == "3"){
//Radio
$valueName = $returnData[$i]["TitleCount"];//題號
$param = "radio_".$valueName;
$change = $_POST[$param];//選的是哪個選項,即ABCD
$homeControllerObj->radioInset($titleid,$userId,$valueName,$type,$change);
}
if($type == "4"){
//此題是多選checkbox
$valueName = $returnData[$i]["TitleCount"];
$param = "chexkbox_".$valueName;
$checkArray = $_POST[$param];
$arrayCount = sizeof($checkArray);//計算陣列長度
for($j=0;$j<$arrayCount;$j++){
$change = $checkArray[$j];
$homeControllerObj->radioInset($titleid,$userId,$valueName,$type,$change);
}
}
}
echo"<script type='text/javascript'>alert('您已作答成功,感謝參與');</script>";
Header("Location: ../home.phtml?userId={$userId}");
Excel匯出ExcelController.php
<?
/** 方法檔案 */
include 'HomeServics.php';
/** PHPExcel */
include '../PHPExcel/PHPExcel.php';
include '../PHPExcel/PHPExcel/Writer/Excel2007.php';
include '../PHPExcel/PHPExcel/IOFactory.php';
$titleid = $_GET["titleid"];
$homeControllerObj = new HomeController();
//獲取所有答題人的Id
$userIdArray = $homeControllerObj->getAllUserId($titleid);
//獲取答題人的數目
$userIdCount = $homeControllerObj->getCountUserid($titleid);
//獲取原題資訊
$QuestArray = $homeControllerObj->getAllData($titleid);
//獲取題目的數目
$QuestCount = $homeControllerObj->getAllDataCount($titleid);
//獲取總題目
$QuestName = $homeControllerObj->getQuestName($titleid);
//標題描述
$QuestDescription = $homeControllerObj->getQuestDescription($titleid);
$objPHPExcel = new PHPExcel();
$objSheet = $objPHPExcel->getActiveSheet();
$objSheetName = $QuestName."作答情況";
$objSheet->setTitle($objSheetName);
$objSheet->setCellValue('A1','TITLE');
$objSheet->setCellValue('B1',$QuestName);
$objSheet->setCellValue('A2','Description');
$objSheet->setCellValue('B2',$QuestDescription);
$sheetOneRow = 3;
for($i=0;$i<$userIdCount;$i++){
$userId = $userIdArray[$i]["UserId"];
$username = $homeControllerObj->getUserNameById($userId);
$objSheet->setCellValue('A'.$sheetOneRow,'使用者名稱:');
$objSheet->setCellValue('B'.$sheetOneRow,$username);
$sheetOneRow ++;
for($j=0;$j<$QuestCount;$j++){
$titleCount = $QuestArray[$j]["TitleCount"];
$smalltitle = $QuestArray[$j]["TitleTitle"];
$objSheet->setCellValue('A'.$sheetOneRow,'問題序號:'); //4
if($QuestArray[$j]["Type"]=="1"){//單選
$smalltitle = "Select.單選——".$titleCount.":".$smalltitle;
$objSheet->setCellValue('B'.$sheetOneRow,$smalltitle);
}
if($QuestArray[$j]["Type"]=="2"){//多
$smalltitle = "Select.多選——".$titleCount.":".$smalltitle;
$objSheet->setCellValue('B'.$sheetOneRow,$smalltitle);
}
if($QuestArray[$j]["Type"]=="3"){//radio
$smalltitle = "Radio——".$titleCount.":".$smalltitle;
$objSheet->setCellValue('B'.$sheetOneRow,$smalltitle);
}
if($QuestArray[$j]["Type"]=="4"){//checkbox
$smalltitle = "Checkbox——".$titleCount.":".$smalltitle;
$objSheet->setCellValue('B'.$sheetOneRow,$smalltitle);
}
$a = "A選項:".$QuestArray[$j]["TitleA"];
$objSheet->setCellValue('C'.$sheetOneRow,$a);
$b = "B選項:".$QuestArray[$j]["TitleB"];
$objSheet->setCellValue('D'.$sheetOneRow,$b);
$c = "C選項:".$QuestArray[$j]["TitleC"];
$objSheet->setCellValue('E'.$sheetOneRow,$c);
$d = "D選項:".$QuestArray[$j]["TitleD"];
$objSheet->setCellValue('F'.$sheetOneRow,$d);
$OpertionArray = $homeControllerObj->getOpertionData($titleid,$titleCount,$userId);
$arraycount = count($OpertionArray);
$sheetOneRow ++;//5
for($k=0;$k<$arraycount;$k++){
if($OpertionArray[$k]["TitleA"]!=null){
$objSheet->setCellValue('C'.$sheetOneRow,'✔');
$sheetOneRow ++;
}
if($OpertionArray[$k]["TitleB"]!=null){
$objSheet->setCellValue('D'.$sheetOneRow,'✔');
$sheetOneRow ++;
}
if($OpertionArray[$k]["TitleC"]!=null){
$objSheet->setCellValue('E'.$sheetOneRow,'✔');
$sheetOneRow ++;
}
if($OpertionArray[$k]["TitleD"]!=null){
$objSheet->setCellValue('F'.$sheetOneRow,'✔');
$sheetOneRow ++;
}
}
}
}
$objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);
// $objWriter->save(str_replace('.php', '.xlsx', __FILE__));
$outputFileName = "outdata.xlsx";
header("Content-Type: application/force-download");
header('Content-Disposition:inline;filename="'.$outputFileName.'"');
header("Content-Transfer-Encoding: binary");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Pragma: no-cache");
$objWriter->save('php://output');
方法集合HomeServics.php
<?php
include 'QuestDao.php';
include 'UserAnswerDao.php';
include 'UserDao.php';
error_reporting(0);
class HomeController{
/**
* 根據titleid刪除所有的相關題目
*
*/
public function delete($titleid){
$questDaoObj = new questDao();
$questDaoObj->deleteTitleData($titleid);
}
/**
* 獲取titleid的題目
*/
public function getQuestName($titleid){
$questDaoObj = new questDao();
$questName = $questDaoObj->getQuestName($titleid);
return $questName;
}
/**
* 獲取titleid的描述
*/
public function getQuestDescription($titleid){
$questDaoObj = new questDao();
$questDescription = $questDaoObj->getQuestDescription($titleid);
return $questDescription;
}
/**
* 獲取資料的數量
*/
public function getAllDataCount($titleid){
$questDaoObj = new questDao();
$returnCount = $questDaoObj->getSumXuhao($titleid);
return $returnCount;
}
/**
* 獲取資料
*/
public function getAllData($titleid){
$questDaoObj = new questDao();
$returnArray = $questDaoObj->getTitleCountdata($titleid);
return $returnArray;
}
/**
* 更新語句
*/
public function update($QuestName,$QuestDescription,$TitleCount,$TitleTitle,$Type,$TitleA,$TitleB,$TitleC,$TitleD,$TitleId){
$questDaoObj = new questDao();
$questDaoObj -> updateQuestData($QuestName,$QuestDescription,$TitleCount,$TitleTitle,$Type,$TitleA,$TitleB,$TitleC,$TitleD,$TitleId);
}
/**
* 啟用狀態更改
*/
public function updateActive($active,$TitleId){
$questDaoObj = new questDao();
$questDaoObj -> updateActiveStatus($active,$TitleId);
}
/**
* 獲取當前的Active
*/
public function getActiveStatus($TitleId){
$questDaoObj = new questDao();
$active = $questDaoObj -> findActive($TitleId);
return $active;
}
/**
* 針對單選的某個選項進行資料庫插入
*/
public function radioInset($titleid,$userId,$titleCount,$type,$change){
$userAnswerDaoObj = new UserAnswerDao();
if($change == "1"){
//單選選了A
$userAnswerDaoObj->aRadio($titleid,$userId,$titleCount,$type,$change);
}
if($change == "2"){
//單選選了B
$userAnswerDaoObj->bRadio($titleid,$userId,$titleCount,$type,$change);
}
if($change == "3"){
//單選選了C
$userAnswerDaoObj->cRadio($titleid,$userId,$titleCount,$type,$change);
}
if($change == "4"){
//單選選了D
$userAnswerDaoObj->dRadio($titleid,$userId,$titleCount,$type,$change);
}
}
/**
* 獲取distinct userid的數量
*/
public function getCountUserid($titleid){
$userAnswerDaoObj = new UserAnswerDao();
$count = $userAnswerDaoObj->getCountUserId($titleid);
return $count;
}
/**
* 刪除答題記錄
*/
public function delectDataByTitleid($titleid){
$userAnswerDaoObj = new UserAnswerDao();
$userAnswerDaoObj->delectDataByTitleid($titleid);
}
/**
* 獲取distinct userid
*/
public function getAllUserId($titleid){
$userAnswerDaoObj = new UserAnswerDao();
$userIdArray = $userAnswerDaoObj->getUserId($titleid);
return $userIdArray;
}
/**
* 獲取某個使用者某個題選取的選項
*/
public function getOpertionData($titleid,$titleCount,$userId){
$userAnswerDaoObj = new UserAnswerDao();
$operationArray = $userAnswerDaoObj->getOpertionData($titleid,$titleCount,$userId);
return $operationArray;
}
/**
* 獲取使用者名稱username根據Id
*/
public function getUserNameById($id){
$userDaoObj = new userDao();
$username = $userDaoObj->getUserNameById($id);
return $username;
}
}
資料庫封裝類
問卷QuestDao.php
<?php
error_reporting(0);
class questDao{
private static $link = null;
/**
* construct
*/
public function __construct(){
self::initDao();
}
/**
* 連結資料庫
*/
public static function initDao(){
self::$link = mysqli_connect('localhost', 'root', '123456', 'zTMtest');
mysqli_set_charset(self::$link, 'utf8');
}
/**
* 關閉資料庫
*/
public static function close(){
self::initDao();
mysqli_close(self::$link);
}
/**
* 顯示錯誤資訊
*/
public static function error($message){
self::initDao();
if($message){
echo "success";
}else{
exit('sql語句執行失敗。錯誤資訊:' . mysqli_error(self::$link));
}
}
/**
* 查詢MAX(TitleId)+1
*/
public static function MaxtitleId(){
self::initDao();
$sql = "SELECT MAX(TitleId)+1 FROM `test` AS maxtitleId;" ;
$maxtitleId = mysqli_query(self::$link, $sql);
$num = mysqli_fetch_assoc($maxtitleId);
$records = implode($num);
return $records;
}
/**
* 根據已經存在的問卷題目和問卷描述查詢Id
*/
public static function delectTitleId($QuestName,$QuestDescription){
self::initDao();
$sql = "SELECT `TitleId` FROM `test` WHERE `QuestName` = '{$QuestName}' AND `QuestDescription`='{$QuestDescription}' ORDER BY Id DESC;" ;
$result = mysqli_query(self::$link, $sql);
$result = mysqli_fetch_all($result, MYSQLI_ASSOC);
//self::error($result);
return $result[0]["TitleId"];
}
/**
* 資料插入到資料庫
*/
public function insertDate($QuestName,$QuestDescription,$TitleCount,$TitleTitle,$Type,$TitleA,$TitleB,$TitleC,$TitleD,$creatby){
self::initDao();
$entitytitleid = self::delectTitleId($QuestName,$QuestDescription);
if($entitytitleid!=null){
$sql_1 = "INSERT INTO test(QuestName,QuestDescription,TitleCount,TitleTitle,Type,TitleA,TitleB,TitleC,TitleD,TitleId,CreatBy) VALUES(?,?,?,?,?,?,?,?,?,?,?);";
$stmt = self::$link ->prepare($sql_1);
$stmt->bind_param('sssssssssss',$QuestName,$QuestDescription,$TitleCount,$TitleTitle,$Type,$TitleA,$TitleB,$TitleC,$TitleD,$entitytitleid,$creatby);
$result=$stmt->execute();
self::error($result);
}else{
$maxtitleid = self::MaxtitleId();
$sql_2 = "INSERT INTO test(QuestName,QuestDescription,TitleCount,TitleTitle,Type,TitleA,TitleB,TitleC,TitleD,TitleId,CreatBy) VALUES(?,?,?,?,?,?,?,?,?,?,?);";
$stmt = self::$link -> prepare($sql_2);
$stmt->bind_param('sssssssssss',$QuestName,$QuestDescription,$TitleCount,$TitleTitle,$Type,$TitleA,$TitleB,$TitleC,$TitleD,$maxtitleid,$creatby);
$result=$stmt->execute();
self::error($result);
}
$data = mysqli_fetch_all($result, MYSQLI_ASSOC);
return $data;
}
/**
* 根據TitleId找到多少題,即找尋唯一的TitleId
*/
public function findDataTitleId(){
self::initDao();
//$sql = "SELECT DISTINCT `TitleId`,`CreatBy` FROM `test` ORDER BY TitleId DESC;";
$sql = "SELECT DISTINCT `TitleId`,`CreatBy` FROM `test`;";
$result = mysqli_query(self::$link, $sql);
$data = mysqli_fetch_all($result, MYSQLI_ASSOC);
return $data;
}
public function findCreatBy(){
}
/**
* 記錄titleID的數量
*/
public function findCountTitleId(){
self::initDao();
$sql = "SELECT DISTINCT `TitleId` FROM `test` ORDER BY TitleId DESC;";
$result = mysqli_query(self::$link, $sql);
$records=mysqli_num_rows($result);
return $records;
}
/**
* 根據titleID找QuestName,即問卷名稱
*/
public function getQuestName($param){
self::initDao();
$sql = "SELECT DISTINCT `QuestName` FROM `test` WHERE TitleId='{$param}'";
$result = mysqli_query(self::$link, $sql);
$resultArray = mysqli_fetch_all($result, MYSQLI_ASSOC);
//self::error($result);
return $resultArray[0]["QuestName"];
}
/**
* 根據titleID刪除問卷
*/
public function deleteTitleData($titleid){
self::initDao();
$sql = "DELETE FROM test WHERE TitleId={$titleid}";
$result = mysqli_query(self::$link, $sql);
self::error($result);
}
/**
* 根據$titleid選擇具體的某一題,按照題號TitleCount輸出
* @return
* @author
*/
public function getTitleCountdata($titleid){
$sql = "SELECT * FROM test WHERE TitleId = {$titleid} Order BY TitleCount;";
$result = mysqli_query(self::$link, $sql);
$resultArray = mysqli_fetch_all($result, MYSQLI_ASSOC);
return $resultArray;
}
/**
* 記錄$titleid每一個題的數量
* @return int
* @author
*/
public function getSumXuhao($titleid){
self::initDao();
$sql = "SELECT * FROM test WHERE TitleId = {$titleid} Order BY TitleCount";
$result = mysqli_query(self::$link, $sql);
//self::error($result);
$records=mysqli_num_rows($result);
return $records;
}
/**
* 根據tityid找尋題目描述QuestDescription
*/
public function getQuestDescription($titleid){
self::initDao();
$sql = "SELECT `QuestDescription` From `test` WHERE TitleId={$titleid} LIMIT 1";
$result = mysqli_query(self::$link, $sql);
$questDescriptionArray = mysqli_fetch_all($result, MYSQLI_ASSOC);
//self::error($result);
return $questDescriptionArray[0]["QuestDescription"];
}
/**
* 找到Active的狀態
*/
public function findActive($TitleId){
self::initDao();
$sql = "SELECT DISTINCT `Active` FROM test WHERE TitleId={$TitleId};";
$result = mysqli_query(self::$link, $sql);
$activeArray = mysqli_fetch_all($result, MYSQLI_ASSOC);
return $activeArray[0]["Active"];
}
/**
* Update Data
*/
public function updateQuestData($QuestName,$QuestDescription,$TitleCount,$TitleTitle,$Type,$TitleA,$TitleB,$TitleC,$TitleD,$TitleId){
self::initDao();
$sql="UPDATE test
SET QuestName=?,QuestDescription=?,TitleCount=?,TitleTitle=?,Type=?,TitleA=?,TitleB=?,TitleC=?,TitleD=?
WHERE TitleCount='{$TitleCount}'
AND TitleId={$TitleId};
";
$stmt = self::$link->prepare($sql);
$stmt->bind_param('sssssssss',$QuestName,$QuestDescription,$TitleCount,$TitleTitle,$Type,$TitleA,$TitleB,$TitleC,$TitleD);
$result=$stmt->execute();
self::error($result);
}
/**
* 改變啟用狀態狀態
*/
public function updateActiveStatus($active,$TitleId){
self::initDao();
$sql = "UPDATE test
SET Active = ?
WHERE TitleId={$TitleId};
";
$stmt = self::$link->prepare($sql);
$stmt->bind_param('s',$active);
$result=$stmt->execute();
self::error($result);
}
}
問卷作答UserAnswerDao.php
<?php
class userAnswerDao{
private static $link = null;
/**
* construct
*/
public function __construct(){
self::initDao();
}
/**
* 連結資料庫
*/
public static function initDao(){
self::$link = mysqli_connect('localhost', 'root', '123456', 'zTMtest');
mysqli_set_charset(self::$link, 'utf8');
}
/**
* 關閉資料庫
*/
public static function close(){
self::initDao();
mysqli_close(self::$link);
}
/**
* 顯示錯誤資訊
*/
public static function error($message){
self::initDao();
if($message){
echo "success";
}else{
exit('sql語句執行失敗。錯誤資訊:' . mysqli_error(self::$link));
}
}
/**
* 單選A選項插入
*/
public function aRadio($titleid,$userId,$titleCount,$type,$change){
self::initDao();
$sql = "INSERT INTO user_answer(UserId,TitleId,TitleCount,Type,TitleA) VALUES(?,?,?,?,?);";
$stmt = self::$link->prepare($sql);
$stmt->bind_param('sssss',$userId,$titleid,$titleCount,$type,$change);
$result=$stmt->execute();
//self::error($result);
}
/**
* 單選B選項插入
*/
public function bRadio($titleid,$userId,$titleCount,$type,$change){
self::initDao();
$sql = "INSERT INTO user_answer(UserId,TitleId,TitleCount,Type,TitleB) VALUES(?,?,?,?,?);";
$stmt = self::$link->prepare($sql);
$stmt->bind_param('sssss',$userId,$titleid,$titleCount,$type,$change);
$result=$stmt->execute();
//self::error($result);
}
/**
* 單選C選項插入
*/
public function cRadio($titleid,$userId,$titleCount,$type,$change){
self::initDao();
$sql = "INSERT INTO user_answer(UserId,TitleId,TitleCount,Type,TitleC) VALUES(?,?,?,?,?);";
$stmt = self::$link->prepare($sql);
$stmt->bind_param('sssss',$userId,$titleid,$titleCount,$type,$change);
$result=$stmt->execute();
//self::error($result);
}
/**
* 單選D選項插入
*/
public function dRadio($titleid,$userId,$titleCount,$type,$change){
self::initDao();
$sql = "INSERT INTO user_answer(UserId,TitleId,TitleCount,Type,TitleD) VALUES(?,?,?,?,?);";
$stmt = self::$link->prepare($sql);
$stmt->bind_param('sssss',$userId,$titleid,$titleCount,$type,$change);
$result=$stmt->execute();
//self::error($result);
}
/**
* 查詢userid 唯一值
*/
public function getUserId($titleid){
self::initDao();
$sql = "SELECT DISTINCT UserId FROM user_answer WHERE TitleId={$titleid} ORDER BY UserId;";
$result = mysqli_query(self::$link, $sql);
$resultArray = mysqli_fetch_all($result, MYSQLI_ASSOC);
//self::error($result);
return $resultArray;
}
/**
* 查詢返回userid 的數量
*/
public function getCountUserId($titleid){
self::initDao();
$sql = "SELECT DISTINCT UserId FROM user_answer WHERE TitleId={$titleid} ORDER BY UserId;";
$result = mysqli_query(self::$link, $sql);
$records= mysqli_num_rows($result);
return $records;
}
/**
* 找userid和某個選項選擇的所有值
*/
public function getOpertionData($titleid,$titleCount,$userId){
self::initDao();
$sql = "SELECT TitleA,TitleB,TitleC,TitleD FROM user_answer WHERE TitleCount='{$titleCount}' AND TitleId={$titleid} AND UserId={$userId};";
$result = mysqli_query(self::$link, $sql);
$resultArray = mysqli_fetch_all($result, MYSQLI_ASSOC);
//self::error($result);
return $resultArray;
}
/**
* 刪除有關題的相關記錄
*/
public function delectDataByTitleid($titleid){
self::initDao();
$sql = "DELETE FROM user_answer WHERE TitleId={$titleid}";
mysqli_query(self::$link, $sql);
//self::error($result);
}
}
使用者UserDao.php
<?php
error_reporting(0);
class userDao{
private static $link = null;
/**
* construct
* @author
*/
public function __construct(){
self::initDao();
}
/**
* 連結資料庫
* @author
*/
public static function initDao(){
self::$link = mysqli_connect('localhost', 'root', '123456', 'zTMtest');
mysqli_set_charset(self::$link, 'utf8');
}
/**
* 關閉資料庫
* @author
*/
public static function close(){
self::initDao();
mysqli_close(self::$link);
}
/**
* 顯示錯誤資訊
* @author
*/
public static function error($message){
self::initDao();
if($message){
echo "success";
}else{
exit('sql語句執行失敗。錯誤資訊:' . mysqli_error(self::$link));
}
}
/**
*
*/
public function getMessage($name,$password){
self::initDao();
$sql = "SELECT * FROM user where username='{$name}'and password='{$password}';";
if($name!=null && $password!=null){
$result = mysqli_query(self::$link, $sql);
self::error($result);
$records=mysqli_num_rows($result);
}
else{
$records = 0;
}
return $records;
}
/**
* 得到使用者id
*/
public function getUserId($name,$password){
self::initDao();
$sql = "SELECT Id FROM user where username='{$name}'and password='{$password}';";
$result = mysqli_query(self::$link, $sql);
$resultArray = mysqli_fetch_all($result, MYSQLI_ASSOC);
//self::error($result);
return $resultArray[0]["Id"];
}
/**
* 得到使用者名稱字
*/
public function getUserNameById($id){
self::initDao();
$sql = "SELECT username FROM user where Id={$id};";
$result = mysqli_query(self::$link, $sql);
$resultArray = mysqli_fetch_all($result, MYSQLI_ASSOC);
//self::error($result);
return $resultArray[0]["username"];
}
/**
* 插入資料
*/
public function insertData($username,$password){
self::initDao();
$sql = "INSERT INTO user(username,password) VALUES(?,?);";
$stmt = self::$link ->prepare($sql);
$stmt->bind_param('ss',$username,$password);
$result=$stmt->execute();
}
}
PHPExcel擴充套件:樣式
設定背景全白
$objPHPExcel = new PHPExcel();
$objPHPExcel->getDefaultStyle()->applyFromArray(
array(
'fill' => array(
'type' => PHPExcel_Style_Fill::FILL_SOLID,
'color' => array('argb' => 'FFFFFFFF')
),
)
);