【问题标题】:Searching multiple mysql tables with codeigniter使用codeigniter搜索多个mysql表
【发布时间】:2014-01-07 05:19:48
【问题描述】:

我知道这已被涵盖,但我正在努力让它发挥作用。我的数据库结构如下:

照片

id
title
description
file_name

照片类别

id
photo_id
category_id

类别

id
name

标签

id
tag_name

照片标签

id
photo_id
tag_id

我要做的是让某人输入一个短语或关键字,然后我在数据库中搜索可能匹配标签、类别,当然还有照片标题和描述的结果,并返回照片数据结果。

如果它有助于我在 codeigniter 中开发。

任何帮助将不胜感激。提前致谢。

【问题讨论】:

  • 告诉我们你尝试了什么。?
  • 请支持新用户,他们也不聪明
  • 你得到答案了吗?
  • 是的,我从你那里得到了答案 Adarsh :)

标签: php mysql codeigniter


【解决方案1】:
As my understand with your question

The function in model

function example($phrase)  //select position
    {
        $this->db->select('*');
        $this->db->from('photo');
        $this->db->join('phototags', 'phototags.photo_id = photo.id', 'left');
                $this->db->join('tags', 'tags.id = phototags.tag_id', 'left');
                $this->db->join('Photo_Category', 'Photo_Category.photo_id = photo.id', 'left');
                $this->db->join('Categories', 'Categories.id = Photo_Category.category_id', 'left');
        $this->db->like('tag_name' , $phrase, 'after');
                $this->db->like('Categories.name' , $phrase, 'after');
                $this->db->like('photo.title' , $phrase, 'after');
                $this->db->like('photo.description' , $phrase, 'after');
        $query = $this->db->get();
        return $query->result_array();
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-08-01
    • 1970-01-01
    • 2013-03-23
    • 2013-11-14
    • 1970-01-01
    • 1970-01-01
    • 2011-09-28
    • 1970-01-01
    相关资源
    最近更新 更多