gpt4 book ai didi

php - 仅获取第一行 AUTO_INCRMENT 列值 - Codeigniter

转载 作者:行者123 更新时间:2023-11-29 21:16:35 24 4
gpt4 key购买 nike

这是我的 Codeigniter 应用程序中的代码,我试图通过它的 id 获取位置
问题是我在检索数据时无法获得一致的结果。

型号

function get_location($id)
{
$this->db->select('locations.id, locations.name_ka, locations.text_ka, locations.keyword_ka, locations.region, locations.latitude, locations.longitude, locations.notes_ka, locations.description_ka, locations.recomendation, locations.img, locations.nature, locations.culture, locations.resort, regions.region_type, regions.region_name_ka, resort.resort_name_ka, nature.nature_name_ka, culture.culture_name_ka, gallery.id, gallery.post_id, gallery.img_link, gallery.gallery_name_ka')
->from('locations','id=$id')
->join('regions', 'regions.id = locations.region','left')
->join('culture', 'culture.id = locations.culture','left')
->join('resort', 'resort.id = locations.resort','left')
->join('nature', 'nature.id = locations.nature','left')
->join('gallery', 'gallery.post_id = locations.id','left')
->where('locations.id='.$id);
$queryo = $this->db->get();
return $queryo->row_array();
}

Controller

function details($id){
$this->load->view('templates/head');
$this->load->view('templates/header');
$details = array(
'location' => $this->Location_model->get_location($id)
);
$this->load->view('one_location', $details);
$this->load->view('templates/end');
}

还有一个问题:它仅获取第一行的“id”。对于其他记录,获取所有内容,但不获取 id。说 'id' = NULL;

输出示例

1st row: array(22) { ["id"]=>string(1) "1" ["name_ka"]=>string(28) "მწვანე ტბა"...
2nd row: array(22) { ["id"]=> NULL ["name_ka"]=> string(37) "ბაზალეთის ტბა"...
49th row:array(22) { ["id"]=> NULL ["name_ka"]=> string(59) "სახლ-მუზეუმი, მუზეუმი, "

我似乎找不到问题所在。

最佳答案

这是因为多个表中的 id 重复...

使用这样的代码:

$this->db->select('locations.id as location_id, gallery.id as gallery_id');

关于php - 仅获取第一行 AUTO_INCRMENT 列值 - Codeigniter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35885286/

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