当前位置:网站首页>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
边栏推荐
- 系统太多,多账号互通如何实现?
- 返回字符串中的最大回文数
- The keytool command
- Based on the statistical QDirStat Qt directory
- 《nlp入门+实战:第八章:使用Pytorch实现手写数字识别》
- 力扣(LeetCode)215. 数组中的第K个最大元素(2022.08.03)
- 元宇宙“吹鼓手”Unity:疯狂扩局,悬念犹存
- Power button (LeetCode) 215. The first K largest elements in the array (2022.08.03)
- kingbaseES V8R2/R3 表在指定表空间,为何显示为默认表空间?
- 基于Qt的目录统计QDirStat
猜你喜欢
随机推荐
Returns the maximum number of palindromes in a string
y86.第四章 Prometheus大厂监控体系及实战 -- prometheus存储(十七)
RSS订阅微信公众号初探-feed43
There are too many systems, how to realize multi-account interworking?
数据湖(二十):Flink兼容Iceberg目前不足和Iceberg与Hudi对比
2022杭电多校联赛第五场 题解
千兆2光8电管理型工业以太网交换机WEB管理X-Ring一键环网交换机
"Introduction to nlp + actual combat: Chapter 8: Using Pytorch to realize handwritten digit recognition"
内网服务器访问远程服务器的端口映射
STM8S105k4t6c---------------Light up LED
6口全千兆二层网管型工业以太网交换机千兆2光4电光纤自愈ERPS环网交换机
数据集类型转换—TFRecords文件
一个属于程序员的七夕节!
十一种概率分布
FPGA解析B码----连载3
sqoop ETL tool
网络工程师入门必懂华为认证体系,附系统学习路线分享
机器学习模型的“可解释性”
数据安全峰会2022 | 美创DSM获颁“数据安全产品能力验证计划”评测证书
自定义通用分页标签02