2013-11-27 42 views
0

嗨,我混淆了這一點。我怎麼能夠使這個查詢進入codeigniter模型查詢?這裏是我的PHP下面php本機查詢codeigniter查詢

$query = "SELECT 
       seminars.id, 
       seminars.thumb, 
       seminars_category.category, 
       seminars_category.url, 
       seminars_category.date, 
       seminars_category.abvr 
       FROM 
       seminars 
       INNER JOIN seminars_category ON seminars_category.id = seminars.category 
       WHERE seminars.id = 1 OR seminars.id = 7 OR seminars.id = 12 OR seminars.id = 20 
       OR seminars.id = 24 OR seminars.id = 29 OR seminars.id= 77 OR seminars.id = 84 OR seminars.id = 103 
       OR seminars.id = 157 OR seminars.id = 187 OR seminars.id = 234 OR seminars.id = 241 OR seminars.id = 308 OR seminars.id = 314 OR seminars.id = 390 
       OR seminars.id = 407 OR seminars.id = 414 OR seminars.id = 429 OR seminars.id = 455 OR seminars.id = 462 OR seminars.id = 511 OR seminars.id = 537 OR seminars.id = 573 
       OR seminars.id = 591 OR seminars.id = 641 
       ORDER BY seminars_category.date DESC 
       " 
       ; 
    $res = mysql_query($query); 

本地查詢我想這放在

public function getAllActivities(){ 

} 

,並在我的位指示在這裏

$this->data['activities'] = $this->am->getAllActivities(); 

有人可以幫助我從PHP本地查詢到笨? ??

感謝

+0

你所有你需要在這裏:http://ellislab.com/codeigniter/user-guide/database/active_record.html –

+0

是的,我知道。它的所有在用戶指南 –

回答

0
$this->db->select('seminars.id, 
      seminars.thumb, 
      seminars_category.category, 
      seminars_category.url, 
      seminars_category.date, 
      seminars_category.abvr'); 
     $this->db->join('seminars_category', 'seminars_category.id = seminars.category', 'inner'); 
     //use a loop here for better implementation of the where-clause 
     $this->db->where('seminars.id =', 1); 
     $this->db->or_where('seminars.id =', 7); 
     $this->db->or_where('seminars.id =', 12); 
     $this->db->order_by('seminars_category.date', 'DESC'); 
     $query = $this->db->get(); 

它不是測試,只是寫有CI的文檔。你可以確定使用DRY併爲where子句實現一個循環。

希望工程或給你至少知道這是怎麼可以工作

+0

確定感謝您的想法.... –

+0

似乎它不能很好地工作 –

+0

你應該使用此調試它:echo $ this-> db-> last_query;你會得到這個SQL。 –