php - codeigniter内部连接错误
问题描述
我想在 Codeigniter 中将一些表与 Inner Join 相等。但我给出了一些错误。我在控制器中放了一些代码。但我给出了这样的错误:
A Database Error Occurred Error Number: HY000/1096 No tables used SELECT * Filename: 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
推荐阅读
- javascript - 在 javascript 中使用 echo'd ++$value 作为 html5 音频播放器页面的一部分时出现问题
- mysql - 通过编写脚本在 mysql Workbench 8.0.19 中导入 .csv 文件
- android - 如何生成不同的调试 sha1-key
- php - 数组中的 Html 代码显示不正确?
- reactjs - 以编程方式附加组件
- python - 设置迷你 Dask 集群
- amazon-web-services - Amazon Corretto 11 不包括 jFX
- discord.js - Discord.js 将人移动到随机 VoiceChannel
- python - 如何在python ffmpeg中组合2个流
- android - Flutter cloud_firestore 包导致应用崩溃