4

我正在 Codeigniter 中做一个项目。在这里,我使用 imap 从我的 gmail id 获取最新的 10 封邮件。在这里,我想获取已获取邮件的 from 字段,并且我想检查已获取邮件的 from 字段是否在我的数据库table('clients')中。在这里,我将 10 from field of fetched mail 存储到数组并将其传递给模型,在那里进行检查并返回匹配的字段名称。但这对我不起作用。

我的控制器功能是:

if ($mbox = imap_open($authhost, $user, $pass)) {
                $emails = imap_search($mbox, 'ALL');
                $some = imap_search($mbox, 'SUBJECT "Suspicious sign in prevented"', SE_UID);
                $MC = imap_check($mbox);
                $inbox = $MC->Nmsgs;
                $inboxs = $inbox - 9;
                if ($emails) {
                    $data['overview'] = imap_fetch_overview($mbox, "$inboxs,$inboxs:$inbox", 0);
                    $i = 0;
                    foreach ($data['overview'] as $i => $val) {

                        $from[$i] = $val->from;
                        $i++;
                    }

                    $data['result'] = $this->crm_model->get_names($from);
                    foreach ($data['result'] as $row) {
                        echo $row->name;echo "<br/>";
                    }

                }
                imap_close($mbox);
            }

我的模型函数是:

function get_names($from) {

    $this->db->select('name');
    $this->db->from('clients');
    $this->db->where_in('name', $from);
    $query = $this->db->get();
    return $query->result();
}

但是当我使用上面的模型函数时,它会返回值

function get_names() {
                  $options = array(
                         '0' => 'Job Openings',
                         '1' => 'Offers',
                         '2' => 'Techgig',
                         '3' => 'Australia',
                        );

        $this->db->select('name');
        $this->db->from('clients');
        $this->db->where_in('name', $options);
        $query = $this->db->get();
        return $query->result();
    }

我认为问题在于将值从控制器传递到模型。谁能帮我。提前致谢

4

2 回答 2

2

使用 where_in(逗号分隔值列表)在数据库中执行任何查询时,值列表应类似于以下数组:

$options = array('Hello', 'World!', 'Beautiful', 'Day!');

不像这样:

 $options = array('0' => 'Job Openings','1' => 'Offers','2' => 'Techgig','3' =>'Australia',);

要做到这一点,你应该内爆这个数组!

$opt=implode(",",$options);

并将这个 $opt 数组传递给 WHERE_IN()

希望这能解决您的问题!

于 2012-12-27T06:33:20.570 回答
1

你不必使用$i..

if ($emails) {
                $data['overview'] = imap_fetch_overview($mbox, "$inboxs,$inboxs:$inbox", 0);
               // $i = 0;
                foreach ($data['overview'] as $val) {

                    $from[] = $val->from;
                    //$i++;
                }

                $data['result'] = $this->crm_model->get_names($from);
                foreach ($data['result'] as $row) {
                    echo $row->name;echo "<br/>";
                }

            }

做这些改变并检查

于 2012-12-27T05:31:37.820 回答