Codeigniter内部联接错误 [英] codeigniter inner join error

查看:81
本文介绍了Codeigniter内部联接错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想与Codeigniter中的Inner Join相等。但是我给出了一些错误。我在控制器中放了一些代码。但是我给出了这样的错误:

I want to equal some table with Inner Join in Codeigniter. But I give some errors. I put below some codes in my controller. But I give an error like that:


发生数据库错误
错误号:HY000 / 1096
没有表使用
SELECT *
文件名:C:/xampp/htdocs/erp/system/database/DB_driver.php
行号:691

A Database Error Occurred Error Number: HY000/1096 No tables used SELECT * Filename: C:/xampp/htdocs/erp/system/database/DB_driver.php Line Number: 691

我的控制器内部在这里加入:

My Controller Inner Join Here:

    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查询生成器获得所需结果

Use ci query builder to get the desired result

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

这篇关于Codeigniter内部联接错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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