簡體   English   中英

從多個表中查詢數據

[英]query data from more than one table

我有一個搜索功能,當前可從一個表中獲取數據,我也想從另一表中獲取數據。

$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 關於如何實現此目標的任何想法?

您可能想稍微復習一下SQL ,尤其是看看SQL Joins

話雖如此,在重新閱讀您的問題之后,您似乎正在嘗試在多個表中的特定列中搜索相當特定的數據。 首先,您可能想研究使用LIKE而不是WHERE

其次,根據您如何顯示結果,您可能會編寫兩個單獨的查詢,然后遍歷每個單獨的結果並顯示它們。 如果表結構確實不同,則可以使用“聯合”或“聯接”,但也可能難以准確顯示結果。

似乎您正在使用ORM /框架來訪問數據,而您正在使用的是哪一個。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM