【问题标题】:Codeigniter - Database selectCodeigniter - 数据库选择
【发布时间】:2011-10-21 02:39:04
【问题描述】:

嗨,

我非常需要与 Codeigniter 相关的帮助。

我在数据库查询方面遇到了一些问题,我是 Codeigniter 的新手。

我有 3 张桌子:

1) film(film_id, filmname) PK (film_id)
2) category(category_id, categoryname) PK (category_id)
3) film_category(contains both primary keys (film_id) and (category_id))

问题是我想select all filmname from film tables where category_id = 3。

如何用活动记录类做到这一点?

请提出建议。

我是 Codeigniter 的新手,我喜欢它。

提前感谢您的朋友。

【问题讨论】:

    标签: mysql codeigniter activerecord


    【解决方案1】:

    类似的东西:

    $this->db->select('f.filmname');
    $this->db->join('film_category fc', 'fc.film_id = f.film_id');
    $this->db->where('fc.category_id', 3);
    $query = $this->db->get('film f');
    

    我发现 ActiveRecord 是 CodeIgniter 中最有用和最优雅的部分之一。

    【讨论】:

      【解决方案2】:

      从数据库中按降序选择数据

      $this->db->order_by("id","desc"); $query = $this->db->get('table_name'); return $query->result();

      【讨论】:

      • 根据表id降序检索表数据
      • 能否请您在答案中添加一些细节?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多