【问题标题】:MySQL Join with file_manage table multiple columnsMySQL Join 与 file_manage 表多列
【发布时间】:2016-02-28 04:08:45
【问题描述】:

我需要使用我的目标表和 file_manage 表创建 JSON 文件。 目标表中的封面图像、横幅图像和图库图像 ID。画廊 ID 被序列化

您可以下载数据库 = https://www.dropbox.com/sh/za4w20fqit27qjg/AACx9T3ArMb_gegAqxRXdUOHa?dl=0

destination table file manage table

【问题讨论】:

标签: mysql json codeigniter arraylist


【解决方案1】:

你应该像这样创建一个模型函数:

function get_json() {
    $q = $this->db->select('cover, banner, gallery')->from('destination');
    $q = $this->db->select('d_id')->from('file_manage');
    $q = $this->db->join('d_id', 'destination.id = file_manage.id', 'left');
    $query = $q->db->get();
    echo json_encode($query->result_array());
    exit;
}

Learn more about codeigniter joins

【讨论】:

  • 感谢您的评论,但这不起作用,我需要完整的数据数组 -- $this->db->select('*'); $this->db->from('destination'); $this->db->join('file_manage', 'file_manage.id = destination.cover','left'); $query = $this->db->get(); $query->result_array();此查询仅加入 cove id,我还需要横幅,并且画廊、画廊 id 被序列化
【解决方案2】:

用这个创建destination_model 模型和something_name_function() 方法:

$this->db->select('cover,banner,gallery');
$this->db->join('d_id', 'destination.id = file_manage.id', 'left');
$query = $this->db->get('destination');
return json_encode($query->result_array());

在控制器中加载你的模型并获取数据

$this->load->model('destination_model');
$json = $this->destination_model->something_name_function();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多