当前位置:网站首页>Senior PHP development case (1) : use MYSQL statement across the table query cannot export all records of the solution
Senior PHP development case (1) : use MYSQL statement across the table query cannot export all records of the solution
2022-08-04 03:32:00 【Missing moment】
in the actual case development process,使用mysqlQuery statements across tables to export database content.但是经过比对,It is always found that the exported records are less than the actual records.经查发现:Some users of the user table are deleted,The result is that the export record cannot be read normally and the export record is missing.
原代码
//$sql = "select a.pro_id,a.user_id,a.pro_serial,a.pro_name,a.pro_category,a.smallCategory,a.threeCategory,a.user_city,a.user_area,a.pro_declarant,b.user_id,b.user_phone,c.pro_id,c.leader_name,c.leader_phone,(CASE a.pro_audit when 0 then '未审核' when 2 then 'District review' when 3 then 'Municipal audit' when 4 then 'Provincial audit' when 5 then '审核完成' when -1 then '退回' END) AS pro_audit,(CASE a.user_surveyor_type when 2 then '县属' when 3 then '市属' when 4 then '省属' END) AS user_surveyor_type,d.pro_id,d.agency_name FROM " . $db->table('project') . " AS a, " . $db->table('user') . " AS b," . $db->table('leader') . " AS c";//", " . $db->table('agency') . " AS d ";
$sql = "select a.pro_id,a.user_id,a.pro_serial,a.pro_name,a.pro_category,a.smallCategory,a.threeCategory,a.user_city,a.user_area,a.pro_declarant,b.user_id,b.user_phone,c.pro_id,c.leader_name,c.leader_phone,(CASE a.pro_audit when 0 then '未审核' when 2 then 'District review' when 3 then 'Municipal audit' when 4 then 'Provincial audit' when 5 then '审核完成' when -1 then '退回' END) AS pro_audit,(CASE a.user_surveyor_type when 2 then '县属' when 3 then '市属' when 4 then '省属' END) AS user_surveyor_type FROM " . $db->table('project') . " AS a, " . $db->table('user') . " AS b," . $db->table('leader') . " AS c";//", " . $db->table('agency') . " AS d ";
$sql .= " WHERE a.user_id = b.user_id AND a.pro_id = c.pro_id";// AND a.pro_id = d.pro_ida.pro_audit <> 0 AND
$sql .= " ORDER BY a.pro_id DESC";
$row = $db->queryall($sql);
$infoName = "项目信息表" . date("Y.m.d");
解决方案
case "exp";
require 'libs/project.export.php';
$sql = "select pro_id,user_id,pro_serial,pro_name,pro_category,smallCategory,threeCategory,user_city,user_area,pro_declarant,(CASE pro_audit when 0 then '未审核' when 2 then 'District review' when 3 then 'Municipal audit' when 4 then 'Provincial audit' when 5 then '审核完成' when -1 then '退回' END) AS pro_audit,(CASE user_surveyor_type when 2 then '县属' when 3 then '市属' when 4 then '省属' END) AS user_surveyor_type FROM " . $db->table('project') . " WHERE 1";
$sql .= " ORDER BY pro_id DESC";
$row = $db->queryall($sql);
//读取用户信息;
foreach ($row as $k => $v) {
$sql_u = "select user_phone from " . $db->table('user');
$sql_u .= " WHERE user_id =" . $v['user_id'];
$row[$k]["user"] = $db->queryall($sql_u);
}
//Read the person-in-charge information;
foreach ($row as $k => $v) {
$sql_l = "select leader_name,leader_phone from " . $db->table('leader');
$sql_l .= " WHERE pro_id =" . $v['pro_id'];
$row[$k]["leader"] = $db->queryall($sql_l);
}
//Read institution information;
foreach ($row as $k => $v) {
$sql_a = "select agency_name from " . $db->table('agency');
$sql_a .= " WHERE pro_id =" . $v['pro_id'];
$row[$k]["leader"] = $db->queryall($sql_a);
}
$infoName = "项目信息表" . date("Y.m.d");
@lockdata.cn
边栏推荐
猜你喜欢
y86.第四章 Prometheus大厂监控体系及实战 -- prometheus存储(十七)
机器学习模型的“可解释性”
自制蓝牙手机app控制stm8/stm32/C51板载LED
Detailed analysis of scaffolding content
4路双向HDMI综合业务高清视频光端机8路HDMI高清视频光端机
一文详解DHCP原理及配置
学会iframe并用其解决跨域问题
Postgresql源码(66)insert on conflict语法介绍与内核执行流程解析
Gigabit 2 X light 8 electricity management industrial Ethernet switches WEB management - a key Ring Ring net switch
哎,又跟HR在小群吵了一架!
随机推荐
基地址:环境变量
sqoop ETL工具
SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropri
Gigabit 2 X light 8 electricity management industrial Ethernet switches WEB management - a key Ring Ring net switch
架构实战营模块三作业
MySQL query optimization and tuning
typescript type 和 interface 的区别
new Date将字符串转化成日期格式 兼容IE,ie8如何通过new Date将字符串转化成日期格式,js中如何进行字符串替换, replace() 方法详解
6口全千兆二层网管型工业以太网交换机千兆2光4电光纤自愈ERPS环网交换机
力扣(LeetCode)215. 数组中的第K个最大元素(2022.08.03)
目标检测-中篇
Y86. Chapter iv Prometheus giant monitoring system and the actual combat, Prometheus storage (17)
【 observe 】 super fusion: the first mention of "calculate net nine order" evaluation model, build open prosperity of power network
用户与用户互发红包/支付宝C2C/B2C现金红包php源码示例/H5方式/兼容苹果/安卓
mq应用场景介绍
FFmpeg —— 录制麦克风声音(附源码)
创新互融|华秋赋能助力OpenHarmony生态硬件开发落地
基于 SSE 实现服务端消息主动推送解决方案
缓存穿透、缓存击穿、缓存雪崩以及解决方案
STM8S105k4t6c--------------点亮LED