drsqpko5286 2012-05-07 10:28 采纳率: 0%
浏览 37

在symfony的表中具有不同字段的非相关表的分页

I want to paginate the records of two DB tables, Table1 and Table2 ,which are not related to each other and both the DB tables have different number of fields.Each query should have some conditions and are joined with some other tables also.

I want to paginate the records of both the table simultaneously so that i can show the data as follows-

Row1 = Table1's - name, address,...
Row2 = Table2's - tool_name, quantity,...
Row3 = Table1's - name, address,...
Row4 = Table2's - tool_name, quantity,...
.
.
.

If there will be no records for table1 then it will paginate table2 and vice versa. I want this to be done on symfony PHP framework.Can somebody help on forming the query for this type of pagination.

  • 写回答

1条回答 默认 最新

  • dongzi5062 2013-01-29 04:25
    关注

    I end up something like this.

    Fetched all the data of different queries and stored into an array and later on cached it.

    foreach($queries as $key => $query) {
     foreach ($query->fetchArray() as $result) {
        $data[] = $result;
     }
    }
    
    $c = new sfFileCache(
        array(
         'cache_dir' => sfConfig::get('sf_cache_dir').'/function',
         'lifetime'  => 3600,
        )
     );
    $c->set('myarray',serialize($data));
    

    I extend the sfDoctrinePager so that it will find total number of pages, etc. for all those queries.

    Than i used PHP usort() to sort the data according to a specific order.

    usort($data, array($this,'activity_sort'));
    

    Then i used PHP array_chunk() to get limited records.

    $chunkedData  = array_chunk($data, $limit);
    $finalData = $chunkedData[$page - 1];
    

    Yes it breaks the rules of pagination but at that time i did not got any better solution that this.

    评论

报告相同问题?

悬赏问题

  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行