0

in my controller i have an associative array in the following pattern!

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

now what i want to do is there is some data on another table where these ids are referenced as foreign keys what i want to do is iterate through this array of ids and fetch data from another table on the basis of these ids! this will be my query

 $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();
3
  • Is there a reason you are not writing a query join, so you are only making one database call? Commented May 16, 2017 at 16:43
  • Search for the word "join" on this page and it will show you how: codeigniter.com/userguide3/database/query_builder.html Commented May 16, 2017 at 16:45
  • for join also i need to iterate this array , this array is returned after a number of conditions so i can thought it would be better if i just uses this array to fetch data from the table moreover i dont need data from multiple table, just from one table so join is not necessary Commented May 16, 2017 at 16:47

1 Answer 1

1

Does this give you enough to complete your work or do you need more? I can't test my code if I include your codeigniter code in there, since I don't have your database.

<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>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.