簡體   English   中英

Codeigniter內部聯接錯誤

[英]codeigniter inner join error

我想與Codeigniter中的Inner Join相等。 但是我給出了一些錯誤。 我在控制器中放了一些代碼。 但是我給出了這樣的錯誤:

發生數據庫錯誤,錯誤號:HY000 / 1096,未使用表SELECT *文件名:C:/xampp/htdocs/erp/system/database/DB_driver.php行號:691

我的控制器內部加入此處:

    public function edit($cusId) {

    $this->lang->load('content', $this->session->userdata('people_lang'));

    $viewData = new stdClass();
    $viewData->customer = $this->db->where("cusId", $cusId)->get("customer")->row();
    $viewData->doctype = $this->db->get("documenttype")->result();
    $viewData->documents = $this->db->get("document")->result();

    $this->db->select('dt.docTypeId,dt.docTypeCat,dt.docTypeNameEn,
 dt.docTypeNameAr,d.docFileDocType,');
    $this->db->from('documenttype dt');
    $this->db->join('document d' ,'d.docFileDocType = dt.docTypeId');

    $query = $this->db->get();
    if ($query->num_rows() > 0 )
    {
        $viewData['document'] = $query->row();
    }

    $this->load->view("file_manager", $viewData);

}

鑒於:

<?php
foreach($documents as $docs){ 
    if(($customer->cusId) == ($docs->docFileCusId)){ ?>
<tr>
    <td data-title="File ID"><?php echo $docs->docFileId; ?></</td>
    <td data-title="Customer Code"><?php echo $customer->cosCode; ?></td>
    <td data-title="Name Surname"><?php echo $customer->cosName.' '.$customer->cosSurname; ?></</td>
    <td data-title="File Type"><?php echo $document->docFileDocType; ?></td>
    <td data-title="Description"><?php echo $docs->docFileDesc; ?></td>
    <td data-title="Create Date"><?php echo $docs->docFileCreateDate; ?></</td>
    <td data-title="File"><a href="<?php echo base_url().'upload/file/customer/'.$docs->docFileDirectory; ?>" download>
    <?php echo $docs->docFileDirectory; ?></a> <i class="fa fa-download"></i></td>
</tr>
<?php }} ?>

希望這個能對您有所幫助:

使用ci查詢生成器獲得所需結果

public function edit($cusId) 
{
   $this->lang->load('content', $this->session->userdata('people_lang'));

   $viewData = array();

   $this->db->select('*');
   /*$this->db->select('dt.docTypeId,dt.docTypeCat,dt.docTypeNameEn,
     dt.docTypeNameAr,d.docFileDocType');*/
   $this->db->from('documenttype dt');
   $this->db->join('document d' ,'d.docFileDocType = dt.docTypeId');
   $this->db->join('customer c' ,'c.cusId = d.docFileId');
   $this->db->where("c.cusId", $cusId)

   $query = $this->db->get();
   if ($query->num_rows() > 0 )
   {
      $viewData['documents'] = $query->result();
   }

   /*print viewData here to make sure it has data or not 
     print_r($viewData);die;
   */
   print_r($viewData);die;
   $this->load->view("file_manager", $viewData);
}

您的視圖應如下所示:

<?php
   foreach($documents as $docs){ ?>
   <tr>
     <td data-title="File ID"><?php  echo $docs->docFileId; ?></</td>
     <td data-title="Customer Code"><?php  echo $docs->cosCode; ?></td>
     <td data-title="Name Surname"><?php  echo $docs->cosName.' '.$docs->cosSurname;  ?></</td>
     <td data-title="File Type"><?php  echo $docs->docFileDocType; ?></td>
     <td data-title="Description"><?php  echo $docs->docFileDesc; ?></td>
     <td data-title="Create Date"><?php  echo $docs->docFileCreateDate; ?></td>
     <td data-title="File">
        <a href="<?php echo base_url().'upload/file/customer/'.$docs->docFileDirectory;?>" download><?php  echo $docs->docFileDirectory; ?>
        </a> <i class="fa fa-download"></i>
    </td>
  </tr>
<?php }  ?>

有關更多信息: https : //www.codeigniter.com/user_guide/database/query_builder.html#selecting-data

暫無
暫無

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

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