循环遍历一组id并获得CI中的数组结果

时间:2017-05-16 16:41:44

标签: php

在我的控制器中,我有一个以下模式的关联数组!

Array ( [0] => Array ( [id] => 13 ) [1] => Array ( [id] => 14 ) ) 

现在我要做的是在另一个表上有一些数据,其中这些id被引用为外键我想要做的是迭代这个id数组并根据这些id从另一个表中获取数据! 这将是我的查询

 $this->db->select("path");
        $this->db->from('main_data');
        $this->db->where("f_key",$id); //this is the id i want to take from array i written above
        $query = $this->db->get();
        return $query->result_array();

1 个答案:

答案 0 :(得分:1)

这是否足以让您完成工作或需要更多工作?如果我在那里包含你的codeigniter代码,我无法测试我的代码,因为我没有你的数据库。

<pre>
<?php
  $arrOfIds = array( array( "id" => 13 ), array( "id" => 14 ));
  foreach($arrOfIds as $row) {
    $id = $row["id"];
    echo $id . "\r\n";
    //remove the echo statement and run your queries and do whatever you need to do
  }
 ?>
</pre>