2011-06-15 162 views
0

我有一個搜索功能,當前從一個表中獲取數據,並且我想從另一個表中獲取數據。查詢來自多個表的數據

$query = $this->db->get('tbl_customer'); 
$this->db->select('in_customer_id, st_company_name, in_customer_type, st_customer_account, st_customer_state_id, flg_customer_account_type, in_status, dt_added_date, st_tag'); 
if(trim($action['searchtxt'])!='') 
    $this->db->like('st_company_name', html_entity_decode($action['searchtxt'])); 

的觀點:

<div class="floatl" style="width:250px;"> 
     <form name="frm" action="<?php echo $index_url; ?>customers/search/" method="post"> 
     <div class="floatl">     
      <input name="Search" type="text" class="textboxsearch" id="Search" onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;" value="<?php if($searchtxt!=''){ echo $searchtxt; } else{ echo 'Search'; }?>" maxlength="50" /> 
     </div> 
      <div class="floatl searchicon"> 
      <input type="image" src="<?=$admin_base_url?>images/textbox_search.gif" alt="" width="22" height="22" /> 
      </div> 
     <br /> 
     <br /> 
     <font class="txt9">(i.e. Company, Account name)</font> 
     </form>   
    </div> 

我想表到另外的搜索被稱爲tbl_admin_user。有關我如何完成此任何想法?

回答

0

你可能想要刷一下你的SQL,特別是看看SQL Joins

就是這樣說的,在重新閱讀你的問題之後,你似乎試圖在多個表格中搜索特定列以獲取相當特定的數據。首先,您可能需要考慮使用LIKE而不是WHERE。其次,根據您顯示結果的方式,您可能會編寫兩個單獨的查詢,然後遍歷每個單獨的結果並顯示它們。聯盟或聯合可能是可能的,但如果表結構真的不同,也可能難以精確地顯示結果。

+0

正確 - 我試圖從多個表中獲取特定的數據並顯示一個基於ID的數組。我實際上只是發現了這一點,這幾乎和我遇到的問題完全一樣:http://www.webmasterworld.com/php/3610400.htm。好奇,如果這個解決方案是一個很好的... – blackessej 2011-06-15 19:36:18

+0

在該論壇上發佈的答案結合獲得更多的知識,我在我的帖子中提到的項目應該讓你順利。 – tplaner 2011-06-15 19:40:33

+0

謝謝@evolve。很有幫助 – blackessej 2011-06-15 19:46:53

0

看來您正在使用ORM /框架來訪問您正在使用的數據。

無論如何,您可能正在尋找joinunion