gpt4 book ai didi

php - 连接表时字段列表中的列不明确 codeigniter

转载 作者:行者123 更新时间:2023-11-29 19:49:11 25 4
gpt4 key购买 nike

我尝试连接两个表并使用 ajax、codeigniter 和 active record 显示数据,但突然显示错误:

Column 'userfile' in field list is ambiguous

表结构:

相册:id_album、judul_album、userfile、userfile_type

照片:id_photo、id_album、judul_photo、userfile、userfile_type

Controller :

public function ajax_list()
{
$list = $this->Photo_model->get_datatables();
$data = array();
$no = $_POST['start'];

foreach ($list as $data_foto)
{
$no++;
$row = array();
$row[] = '<p style="text-align: center">'.$no.'</p>';
$row[] = '<p style="text-align: left">'.$data_foto->judul_foto.'</p>';
$row[] = '<p style="text-align: left">'.$data_foto->id_album.'</p>';
$row[] = '<p style="text-align: center"><img src="'.base_url('assets/images/photo/').$data_foto->userfile.$data_foto->userfile_type.'" width="100px"></p>';

$row[] = "
<p style='text-align: center'>
<a class='btn btn-sm btn-warning' href='".base_url('admin/photo/update/').$data_foto->id_photo."' title='Edit'><i class='fa fa-pencil'></i> EDIT</a>
</p>
<p style='text-align: center'>
<a class='btn btn-sm btn-danger' href='".base_url('admin/photo/delete/').$data_foto->id_photo."', onClick=\"return confirm('Are you sure?');\"><i class='glyphicon glyphicon-trash'></i> DELETE</a>
</p>";

$data[] = $row;
}

$output = array(
"draw" => $_POST['draw'],
"recordsTotal" => $this->Photo_model->count_all(),
"recordsFiltered" => $this->Photo_model->count_filtered(),
"data" => $data
);
//output to json format
echo json_encode($output);
}

型号:

public function get_datatables()
{
$this->_get_datatables_query();
if($_POST['length'] != -1)
$this->db->select('id_foto,judul_foto,foto_seo,ket,userfile as ufile,userfile_type as ufile_type');
$this->db->join('album ', 'album.id_album = foto.id_photo');

$query = $this->db->get();

return $query->result();
}

任何帮助将不胜感激。

最佳答案

您需要指定要从哪个表获取具有相同名称的列。例如。 album.id_albumphoto.id_album。所以你选择的应该是这样的

$this->db->select('id_foto,judul_foto,foto_seo,ket,[album|photo].userfile as ufile,[album|photo].userfile_type as ufile_type');

[album|photo] 替换为您需要该列来自的表。如果您两者都需要它,那么下面的内容就可以了

$this->db->select('id_foto,judul_foto,foto_seo,ket,album.userfile as album_ufile,album.userfile_type as album_ufile_type,photo.userfile as photo_ufile,photo.userfile_type as photo_ufile_type');

关于php - 连接表时字段列表中的列不明确 codeigniter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40865757/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com