当前位置:网站首页>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
边栏推荐
- STM8S-----选项字节
- There are too many systems, how to realize multi-account interworking?
- KingbaseES数据库启动失败,报“内存段超过可用内存”
- STM8S105k4t6c--------------点亮LED
- 拿捏JVM性能优化(自己笔记版本)
- 出现504怎么办?由于服务器更新导致的博客报504错误[详细记录]
- MRS: Introduction to the use of Alluxio
- 安装postgis时报找不到“POSTGIS_VERSION”这个函数
- Brush esp8266-01 s firmware steps
- 本周四晚19:00知识赋能第4期直播丨OpenHarmony智能家居项目之设备控制实现
猜你喜欢
【 observe 】 super fusion: the first mention of "calculate net nine order" evaluation model, build open prosperity of power network
一个属于程序员的七夕节!
Shell 函数
6口全千兆二层网管型工业以太网交换机千兆2光4电光纤自愈ERPS环网交换机
自制蓝牙手机app控制stm8/stm32/C51板载LED
小程序+新零售,玩转行业新玩法!
【Ryerson情感说话/歌唱视听数据集(RAVDESS) 】
《nlp入门+实战:第八章:使用Pytorch实现手写数字识别》
复制带随机指针的链表
"Introduction to nlp + actual combat: Chapter 8: Using Pytorch to realize handwritten digit recognition"
随机推荐
Postgresql源码(66)insert on conflict语法介绍与内核执行流程解析
Returns the maximum number of palindromes in a string
系统太多,多账号互通如何实现?
STM8S项目创建(STVD创建)---使用 COSMIC 创建 C 语言项目
MySQL查询优化与调优
docker+网桥+redis主从+哨兵模式
【Ryerson情感说话/歌唱视听数据集(RAVDESS) 】
如何读取 resources 目录下的文件路径?
SQL injection in #, - +, - % 20, % 23 is what mean?
Brush esp8266-01 s firmware steps
一文看懂推荐系统:召回04:离散特征处理,one-hot编码和embedding特征嵌入
数据安全峰会2022 | 美创DSM获颁“数据安全产品能力验证计划”评测证书
机器学习之视频学习【更新】
企业直播风起:目睹聚焦产品,微赞拥抱生态
返回字符串中的最大回文数
复现20字符短域名绕过
uni-app 从零开始-基础模版(一)
一文看懂推荐系统:召回05:矩阵补充、最近邻查找,工业界基本不用了,但是有助于理解双塔模型
外卖店优先级
数组相关 内容 解析