业务经理

微信扫描以上二维码

028-61286886

技术咨询

如果多表合并查询 3个以上?

迅睿框架 更新 2020-03-12 03:54:47 清萌网络科技

模板标签里面

如果多表合并查询 3个以上?

        {sql sql='select * from dr_1_zikao union all select * from dr_1_chengkao union all select * from dr_1_zsben union all select * from dr_1_dianda union all select * from dr_1_yuanch' page=1 pagesize=2 urlrule=index.php?s=info&c=category&id=1&page=[page]}
        <li>
            <div class="list_l_b_img fl">
                <img src="{dr_thumb($t['thumb'], 135, 75)}" alt="">
            </div>
            <div class="list_l_b_tit fl">
                <h3><a href="{$t['url']}">{$t['title']}</a></h3>
                <div class="list_zbrq">
                    <span>责编:{$t.author}</span>
                    <span>{dr_date($t['_updatetime'], 'Y-m-d')}</span>
                </div>
            </div>
        </li>
        {/sql}{$debug}
SQL: select * from dr_1_zikao union all select * from dr_1_chengkao union all select * from dr_1_zsben union all select * from dr_1_dianda union all select * from dr_1_yuanch LIMIT 8,2总记录:9分页:已开启当前页:5总页数:5每页数量:2分页地址:index.php?s=info&c=category&id=1&page=[page]可用字段:id、catid、title、thumb、keywords、description、hits、uid、author、status、url、link_id、tableid、inputip、inputtime、updatetime、comments、avgsort、displayorder、related、area

现在只能调出

select * from dr_1_zikao union all select * from dr_1_chengkao 的结果
union all如何多个表合并呢?


方案

  • 清萌网络科技 #1 · 2020-03-11 12:24:38
    满意答案
    增加悬赏(设置悬赏)金:3元,希望大家给予帮助!
  • 迅睿框架创始人 #2 · 2020-03-11 12:25:05
    只能用这种sql标签,来写原始的查询语句,但效率会很低,建议问问数据库设计人员看看怎么写sql才合理
  • 清萌网络科技 #3 · 2020-03-11 14:19:52
    回复迅睿框架创始人 {sql sql='select * from ((select * from dr_1_zikao order by updatetime desc) union all (select * from dr_1_chengkao order by updatetime desc) union all (select * from dr_1_zsben order by updatetime desc) union all (select * from dr_1_dianda order by updatetime desc) union all (select * from dr_1_yuanch order by updatetime desc)) as temp order by updatetime desc '}
    <li>
    <div class="list_l_b_img fl">
    <img src="{dr_thumb($t['thumb'], 135, 75)}" alt="">
    </div>
    <div class="list_l_b_tit fl">
    <h3><a href="{$t['url']}">{$t['title']}</a></h3>
    <div class="list_zbrq">
    <span>责编:{$t.author}</span>
    <span>{dr_date($t['_updatetime'], 'Y-m-d')}</span>
    </div>
    </div>
    </li>
    {/sql}{$debug} 这样可以查询 但是 page=1 pagesize=2 urlrule=index.php?s=info&c=category&id=1&page=[page] sql里加这个分页会报一堆错,不用这个sql语句可以查询 也能分页 不知道这里为什么不能分页了
  • 清萌网络科技 #4 · 2020-03-11 14:20:41
    增加悬赏(设置悬赏)金:2元,希望大家给予帮助!
  • 清萌网络科技 #5 · 2020-03-11 14:23:14
            {sql sql='select * from ((select * from dr_1_zikao order by updatetime desc) union all (select * from dr_1_chengkao order by updatetime desc) union all (select * from dr_1_zsben order by updatetime desc) union all (select * from dr_1_dianda order by updatetime desc) union all (select * from dr_1_yuanch order by updatetime desc)) as temp order by updatetime desc ' page=1 pagesize=2 urlrule=index.php?s=info&c=category&id=1&page=[page]}
            <li>
                <div class="list_l_b_img fl">
                    <img src="{dr_thumb($t['thumb'], 135, 75)}" alt="">
                </div>
                <div class="list_l_b_tit fl">
                    <h3><a href="{$t['url']}">{$t['title']}</a></h3>
                    <div class="list_zbrq">
                        <span>责编:{$t.author}</span>
                        <span>{dr_date($t['_updatetime'], 'Y-m-d')}</span>
                    </div>
                </div>
            </li>
            {/sql}{$debug}
    这里能同时查询5个表,但是分页报错
    		
    
    			
    mysqli_sql_exception #1054
    
    			
    Unknown column 'updatetime' in 'order clause'				
    			
    SELECT count(*) as c FROM ((SELECT count(*) as c FROM 
    dr_1_zikao order by updatetime desc) union all (SELECT count(*) as c 
    FROM dr_1_chengkao order by updatetime desc) union all (SELECT count(*) 
    as c FROM dr_1_zsben order by updatetime desc) union all (SELECT 
    count(*) as c FROM dr_1_dianda order by updatetime desc) union all 
    (SELECT count(*) as c FROM dr_1_yuanch order by updatetime desc)) as 
    temp order by updatetime desc
               		
    
    	
    如下简单的查询就能分页
            {sql sql='select * from dr_1_zikao union all select * from dr_1_chengkao' page=1 pagesize=2 urlrule=index.php?s=info&c=category&id=1&page=[page]}
            <li>
                <div class="list_l_b_img fl">
                    <img src="{dr_thumb($t['thumb'], 135, 75)}" alt="">
                </div>
                <div class="list_l_b_tit fl">
                    <h3><a  target="_blank" href="{$t['url']}">{$t['title']}</a></h3>
                    <div class="list_zbrq">
                        <span>责编:{$t.author}</span>
                        <span>{dr_date($t['_updatetime'], 'Y-m-d')}</span>
                    </div>
                </div>
            </li>
            {/sql}{$debug}
  • 二开/定制/使用解答专家 #6 · 2020-03-11 14:29:38
    union all 联合查询不能使用select *,需要共同字段才可以,看看SQL文档是怎么说的,哈哈,select改成指定字段
  • 清萌网络科技 #7 · 2020-03-11 14:45:52
    二开/定制/使用解答专家 按你这个帖子方法改的https://www.xunruicms.com/wenda/8050.html 我这几个表字段都是相同的 *也能调用出来,就是不能用迅睿的方法分页
            {php $query=' select * from ((select title,thumb,updatetime,author from dr_1_zikao order by updatetime desc) union all (select title,thumb,updatetime,author from dr_1_chengkao order by updatetime desc) union all (select title,thumb,updatetime,author from dr_1_zsben order by updatetime desc) union all (select title,thumb,updatetime,author from dr_1_dianda order by updatetime desc) union all (select title,thumb,updatetime,author from dr_1_yuanch order by updatetime desc)) as temp order by updatetime desc ';}
            {sql sql='$query' page=1 pagesize=2 urlrule=index.php?s=info&c=category&id=1&page=[page]}
            <li>
                <div class="list_l_b_img fl">
                    <img src="{dr_thumb($t['thumb'], 135, 75)}" alt="">
                </div>
                <div class="list_l_b_tit fl">
                    <h3><a href="{$t['url']}">{$t['title']}</a></h3>
                    <div class="list_zbrq">
                        <span>责编:{$t.author}</span>
                        <span>{dr_date($t['_updatetime'], 'Y-m-d')}</span>
                    </div>
                </div>
            </li>
            {/sql}{$debug}
    上面上修改后的 下面是报错
    		
    
    			
    mysqli_sql_exception #1054
    
    			
    
    				Unknown column 'updatetime' in 'order clause'				
    			
    SELECT count(*) as c FROM ((SELECT count(*) as c FROM 
    dr_1_zikao order by updatetime desc) union all (SELECT count(*) as c 
    FROM dr_1_chengkao order by updatetime desc) union all (SELECT count(*) 
    as c FROM dr_1_zsben order by updatetime desc) union all (SELECT 
    count(*) as c FROM dr_1_dianda order by updatetime desc) union all 
    (SELECT count(*) as c FROM dr_1_yuanch order by updatetime desc)) as 
    temp order by updatetime desc
               		
    
    	
    \dayrui\System\Database\MySQLi\Connection.php at line 330					
    				
    323             $this->connID->next_result();324             if ($res = $this->connID->store_result())325             {326                 $res->free();327             }328         }329 330         return $this->connID->query($this->prepQuery($sql));331     }332 333     //--------------------------------------------------------------------334 335     /**336      * Prep the query337      *
    			
    大哥帮忙看看有什么办法能分页吗
  • 清萌网络科技 #8 · 2020-03-11 14:47:26
    增加悬赏(设置悬赏)金:5元,希望大家给予帮助!
  • 清萌网络科技 #9 · 2020-03-11 14:48:41
    一添加
    {sql sql='$query' page=1 pagesize=2 urlrule=index.php?s=info&c=category&id=1&page=[page]}
    分页就报错
  • 二开/定制/使用解答专家 #10 · 2020-03-11 16:05:08
    简单啊
  • 清萌网络科技 #11 · 2020-03-11 16:17:47
    二开/定制/使用解答专家 大佬帮下忙吧 ,同样用select * from dr_1_zikao union select * from dr_1_dianda union select * from dr_1_zsben union select * from dr_1_chengkao union select * from dr_1_yuanch union select * from dr_1_zsben union来合并数据表,加上
    page=1 pagesize=2 urlrule=index.php?s=info&c=category&id=1&page=[page]
    就只能调用第一第二个表的数据,能分页,去掉
    page=1 pagesize=2 urlrule=index.php?s=info&c=category&id=1&page=[page]
    就能调用全部五个表数据 怎么解决这两个冲突呢
  • 清萌网络科技 #12 · 2020-03-12 03:54:47
    @清萌网络科技:66666666666666666

迅睿系统漏洞

图片格式转化
图片格式转化(2026-10-17)
修复百度编辑器里的内容图片没有转换为webp格式 历史文章列表不显...
站群分站系统
站群分站系统(2026-10-15)
子站域名新增llms.txt访问
图书阅读系统
图书阅读系统(2026-10-14)
全站移动端样式适配 首页分类 Tab 横滑容器,左右渐变滚动提示 ...
GEO系统
GEO系统(2026-10-14)
修复下载zip空白地址问题 修复流量复刻和任务队列错误
GeoSeo收录宝
GeoSeo收录宝(2026-10-14)
新增 站长工具箱 前端首页自动调用meta 数据
滑块验证码 Gocaptcha
滑块验证码 Gocaptcha(2026-10-13)
基于开源项目 go-captcha 的行为验证码插件,滑动拼图、区域...
GeoSeo工具箱
GeoSeo工具箱(2026-10-13)
优化巡检任务
GeoSeo排名助手
GeoSeo排名助手(2026-10-11)
加入大模型自定义
SEO聚合关键字
SEO聚合关键字(2026-10-11)
优化关键字列表页最多支持1万篇文章,过多会导致服务器扛不住;