因为考虑到要统计反馈中有多少条是未处理的,多少条是已经处理的,本来将所有反馈类目全部作为数据表里的单独的字段放在同一个表里,比如1条反馈中有“大荤份量”,“小荤份量”,“甜点份量”等近二十个字段,都是单独的字段,统计起来会很麻烦,至少Sham作为新手,不知道何从下手,于是就考虑换种方式,将字段精简,将1条反馈表中分为“反馈类型”,“反馈内容”,“反馈处理”,“处理状态”等字段,然后将原来的类目作为数据值存入对应的字段中。
这里就涉及到如何将一个表单写入多条数据库数据,参考代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
<?php include_once("../public/con.php"); //连接到数据库 $sql = "INSERT INTO ctfeedback (id, name, openid, ctfb_type, ctfb_subtype, ctfb_details, ctfb_fbstatus, ctfb_actions, ctfb_acstatus, ctfb_month) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; //?号需要对应前面字段的数量 // 为 mysqli_stmt_prepare() 初始化 statement 对象 $stmt = mysqli_stmt_init($con); //预处理语句 if (mysqli_stmt_prepare($stmt, $sql)) { // 绑定参数 其中ssssssssss为类型,s的数量要对应字段的数量 mysqli_stmt_bind_param($stmt, 'ssssssssss', $id, $name, $openid, $ctfb_type, $ctfb_subtype, $ctfb_details, $ctfb_fbstatus,$ctfb_actions, $ctfb_acstatus, $ctfb_month); // 设置参数并执行 if($_GET['wt_zczdj']!==null && $_GET['wt_zczdj']!=='' ){ //当表中wt_zczdj存在并且值不为空时,执行下面代码 $id = $_GET["id"]; $name = $_GET["name"]; $openid = $_GET["openid"]; //读取用户微信openid,唯一,便于后期用户读取自己的反馈内容 $ctfb_month = date("Y年m月"); //自动获取当前年月 $ctfb_type = "分量反馈"; //原来是单独数据表,现在和服务及安全反馈并入一张表,最后通过小程序传值获取对应数据 $ctfb_subtype = "早餐"; //为了更细分类 $ctfb_details = $_GET["wt_zczdj"]; //这个是原来存入单独字段的数据,现在统一存放到details字段内 $ctfb_fbstatus ="待审核"; //用于后期审核更改值之后,在月度报表中显示 $ctfb_actions = "待处理"; //这个是用于最后月度报表中,用于统计有多少是还没反馈处理的字段 $ctfb_acstatus=""; mysqli_stmt_execute($stmt); } if($_GET['wt_zcjd']!==null && $_GET['wt_zcjd']!=='' ){ $id = $_GET["id"]; $name = $_GET["name"]; $openid = $_GET["openid"]; $ctfb_month = date("Y年m月"); $ctfb_type = "分量反馈"; $ctfb_subtype = "早餐"; $ctfb_details = $_GET["wt_zcjd"]; $ctfb_fbstatus ="待审核"; $ctfb_actions = "待处理"; $ctfb_acstatus=""; mysqli_stmt_execute($stmt); } //如果还有,则继续参考上面if开始的内容添加 } ?> |
当然,还可以通过另外一种方法来添加多条信息,因为Sham的小程序表单是可选的,所以貌似不适用,贴出来留存分享下,将插入数据库的代码更改为如下:
1 2 3 4 5 6 |
$sql = "insert into guests (type, status) values ('$type1', '$status1')"; $sql .= "insert into guests (type, status) values ('$type2', '$status2')"; $sql .= "insert into guests (type, status) values ('$type3', '$status3')"; |
最新评论