$ C有2个或多个表$ cIgniter Active Record的选择 [英] CodeIgniter Active Record select with 2 or more tables

查看:126
本文介绍了$ C有2个或多个表$ cIgniter Active Record的选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的老code这条SQL语句的设置,并希望将其移动到活动记录,我正在逐步与是我怎么做一个

I have this sql statement setup in my old code and want to move it over to active record, the problem that I'm phased with is how do I do a

 SELECT news_items.id FROM 

 (SELECT news_items.* FROM news_items 
 JOIN feeds ON feeds.id=news_items.feed 
 LEFT JOIN news_item_country ON news_item_country.id=news_items.country 
 WHERE news_items.id=30758 
 ORDER BY date_item DESC ) 

 AS news_items

 GROUP BY news_items.id 
 ORDER BY date_item DESC

试图与活动记录做到这一点,首先我创建了云内选择至少选择是什么,我认为需要做的事情。

Trying to do this with Active Record, first I created the select that goes inside the select at least that is what I think needs to be done.

$news_items = $this->db->select('default_news_items.*')
              ->from('default_news_items ')
              ->join('default_feeds','default_feeds.id=default_news_items.feed')
->join('default_news_item_country','default_news_item_country.id=default_news_items.country','left')
->join('default_news_item_options','default_news_item_options.id=default_news_items.options','left')
              ->where($where)                        
              ->order_by('date_item DESC')
              ->limit($limit)
              ->get();               

接下来,我创建实际的选择并引用其它精选内从

Next I create the actual select and reference the other select inside the from

    if ($query = $this->db->select("
                            news_items.id,
                    ->from($news_items)
                    ->group_by('news_items.id')
                    ->get()) {

它没有工作,所以我问,如果有人有这个和经验怎么办呢?

It did not work, so I'm asking if someone have experiences with this and how to do it?

推荐答案

看看我的这个答案,这可能帮助你如何实现它。

Take a look at this answer of mine this might help how you can achieve it.

<一个href="http://stackoverflow.com/questions/11023318/using-mysql-where-in-clause-in-$c$cigniter/11031431#11031431">Using Mysql的凡在codeigniter条款

这篇关于$ C有2个或多个表$ cIgniter Active Record的选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆