0

I'm attempting to loop through an array and use the rows(values) as the conditions for my SQL query but I can't seem to get it loop through the rows. It only outputs the data for the first row where the form_name = ' V243823' then stops. i need all the rows, so 3 arrays total to be returned.

Campus Forms Array

[0] => Array
        (

            [PQ_Lookup] => V243823
            [RL_Lookup] => B3823RL
            [MA_Lookup] => F356823
        )

Query

    foreach( $campus_forms[0] as $key => $row )
    {
    $this->db->select('form_deadline,form_url,form_fullname'); 
    $this->db->from('form_deadlines');

    $this->db->where('form_name', $row);
        $query = $this->db->get();

         if ($query->num_rows() > 0)
            {
                $campus_forms = $query->result_array();
                  return $campus_forms;
            }
      }
2
  • 2
    You're returning after you get through the first foreach, which exits the function. You probably want to append/merge that result to another array instead. Commented Aug 29, 2013 at 20:45
  • so something like $new_forms = array(); array_push($new_forms, $campus_forms); would that be best? Commented Aug 29, 2013 at 20:50

1 Answer 1

1

In first loop you are returning for this reason it doesn't execute next loop.Please return your data after foreach loop.You can hold your data in an array in every loop.You can do it in this way:

$form_data_array = array();

foreach( $campus_forms[0] as $key => $row )
    {
    $this->db->select('form_deadline,form_url,form_fullname'); 
    $this->db->from('form_deadlines');

    $this->db->where('form_name', $row);
        $query = $this->db->get();

         if ($query->num_rows() > 0)
            {
                $campus_forms = $query->result_array();
                 // return $campus_forms;
$form_data_array[] = $campus_forms;
            }
      }
return $form_data_array;
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.