获得列值的数组codeigniter [英] get array of column values in codeigniter

查看:116
本文介绍了获得列值的数组codeigniter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这种结构的表格:

ID INT(11)

ID int(11)

USER_ID INT(11)

user_id int(11)

notification_event_id INT(11)

notification_event_id int(11)

我怎样才能得到一个包含user_id列的所有值的数组:

how can i get an array that contains all values of user_id column :

EX:

EX:

Array([0]=> 1,[1]=>2,[2]=>3,[3]=>4,[4]=>5,[5]=>6);

和不循环的 result_array()值和移动user_ids到一个新的整数数组

and without looping on the result_array() value and moving the user_ids to a new integers array

这可能吗?

推荐答案

每个结果行本身是一个数组等等的部分的循环是必须的!为什么你需要做不同呢?

Each results row is itself an array so some looping is necessary! Why would you need to do it differently?

最直接的方式做你想要的是:

The most straightforward way to do what you want is:

// Model
function get_all_userid()
{
    $query = $this->db->get('table_name');
    $array = array();

    foreach($query->result() as $row)
    {
        $array[] = $row['user_id']; // add each user id to the array
    }

    return $array;
}

// Controller
function user_list()
{
    $data = $this->your_model->get_all_userid(); // get results array from model
    $this->load->view('your_view', $data); // pass array to view
}

显然,你需要调整表/型号名称以匹配您正在使用的人。

Obviously you'll need to adjust the table/model names to match the ones you're using.

这篇关于获得列值的数组codeigniter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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