如何通过在codeigniter中循环遍历数组来搜索表

时间:2013-12-15 20:35:41

标签: php codeigniter

我有一个名字数组,我需要从数据库中获取每个名称的全名。在下面的代码中,我设法获得用户的朋友/朋友的列表,然后将该字符串转换为数组。但是我无法获取数组中名称的全名,请帮助:(

这是我的模特

public function getPals(){
    $username = $this->session->userdata('username');
    $query = $this->db->get_where('pals', array('username' => $username));

    foreach ($query->result() as $row){

        $palString = $row->pal_list;   //returns a string "james,nash" from db

        $palsArray = explode(",", $palString);

        foreach ($palsArray as $pals) {

            $query = $this->db->get_where('users', array('username' => $pals));

            foreach ($query->result() as $row){

                $pal = $row->full_name;

                //nothing is returned, am pretty sure nash exists in the db
                echo $pal;
                echo "<br>";
            }
        }
    }
}

0 个答案:

没有答案