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:
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);
}
In view :
<?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 }} ?>
$viewData['document'] = $query->row();overwrites the object created with$viewData = new stdClass();with an array. Stick with the object and use$viewData->document = $query->row();- DFriend