太阳成游戏网站

联系官方销售客服

QQ1835022299

028-61286886

太阳成游戏网站框架 版主:太阳成游戏网站框架研发组
如果多表合并查询 3个以上?
类型:太阳成游戏网站CMS 更新时间: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]}
        
  •                                           
  •                              

    {$t['title']}

                                         责编:{$t.author}                     {dr_date($t['_updatetime'], 'Y-m-d')}                 
                
                     {/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
      Firefox 73.0 0
      增加悬赏(设置悬赏)金:3元,希望大家给予帮助!
      满意答案
    • #2楼    太阳成游戏网站框架创始人
      2020-03-11 12:25:05
      Chrome 0
      只能用这种sql标签,来写原始的查询语句,但效率会很低,建议问问数据库设计人员看看怎么写sql才合理
    • 清萌网络科技
      #3楼    清萌网络科技
      2020-03-11 14:19:52
      Firefox 73.0 0
      回复太阳成游戏网站框架创始人 {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 '}





    • {$t['title']}



      责编:{$t.author}
      {dr_date($t['_updatetime'], 'Y-m-d')}



    • {/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
    Firefox 73.0 0
    增加悬赏(设置悬赏)金:2元,希望大家给予帮助!
  • 清萌网络科技
    #5楼    清萌网络科技
    2020-03-11 14:23:14
    Firefox 73.0 0
            {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]}
            
  • {$t['title']}

    责编:{$t.author} {dr_date($t['_updatetime'], 'Y-m-d')}
  • {/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]}
            
  • {$t['title']}

    责编:{$t.author} {dr_date($t['_updatetime'], 'Y-m-d')}
  • {/sql}{$debug}
  • 二开/定制/使用解答专家
    #6楼    二开/定制/使用解答专家
    2020-03-11 14:29:38
    Chrome 0
    union all 联合查询不能使用select *,需要共同字段才可以,看看SQL文档是怎么说的,哈哈,select改成指定字段
  • 清萌网络科技
    #7楼    清萌网络科技
    2020-03-11 14:45:52
    Firefox 73.0 0
    二开/定制/使用解答专家 按你这个帖子方法改的/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]}
            
  • {$t['title']}

    责编:{$t.author} {dr_date($t['_updatetime'], 'Y-m-d')}
  • {/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
    Firefox 73.0 0
    增加悬赏(设置悬赏)金:5元,希望大家给予帮助!
  • 清萌网络科技
    #9楼    清萌网络科技
    2020-03-11 14:48:41
    Firefox 73.0 0
    一添加
    {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
    小米手机 0
    简单啊
  • 清萌网络科技
    #11楼    清萌网络科技
    2020-03-11 16:17:47
    Firefox 73.0 0
    二开/定制/使用解答专家 大佬帮下忙吧 ,同样用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
    Firefox 73.0 0
    @清萌网络科技:66666666666666666