Codeigniter不同的mysql查询 [英] codeigniter distinct mysql query

查看:73
本文介绍了Codeigniter不同的mysql查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当我在模型中使用get_where时,它就会为我提供所有数据库条目(包括重复项),而当我使用get时,它只会为我提供第一个条目.但是我想要所有不同的条目.谁能帮我.非常感谢!

whenever I use get_where in the model it gives me all database entries including duplications and when I use get only it only gives me the first entry. But I want all distinct entries. Can anyone help me please. Thanks a lot!

Controler = site.php:

Controler = site.php:

public function western_australia(){
    $this->load->model("continents_get");
    $data["results"] = $this->continents_get
                            ->getMaincategories("western_australia");
    $this->load->view("content_western_australia", $data);
}

model = continents_get.php

model = continents_get.php

function getMaincategories($western_australia){
    $this->db->distinct();
    $query = $this->db->get_where("p_maincategories", 
                    array("page" => $western_australia));
    return $query->result();
}

view = content_western_australia.php

view = content_western_australia.php

<?php
    foreach($results as $row){
        $page = $row->page;
        $main_en = $row->main_en;
        echo $main_en; 
?>

推荐答案

区别并不总是有效.您应该添加->group_by("name_of_the_column_which_needs_to_be unique");

Distinct will not always work. You should add ->group_by("name_of_the_column_which_needs_to_be unique");

这篇关于Codeigniter不同的mysql查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆