Below is my model, it works correctly. Right now it is returning false because there are no records for a new student. However in my controller, I have an If statement that checks to see if the query is returned true then loops through every row in the query:
My Model:
function get_schedule($Student_ID)
{
$query = $this -> db -> query("
getstuff");
if($query -> num_rows() > 0 )
{
$sections= $query->result();
return $sections;
}
else
{
return false;
}
}
My Controller:
$Student_ID = $session_data['Student_ID'];
$query['section']= $this->grades_model->get_schedule($Student_ID);
$sections= array();
if ($query == TRUE)
{
foreach($query['section'] as $row)
{
do stuff:
}
}
The problem is it’s giving me an invalid foreach loop warning because there is no data to loop through. How can I make it so it does not even attempt that loop if query is returned false. I tried adding elseif($query == FALSE){}, but still invalid foreach loop.
What gives, and can I just suppress that warning?
It is not ‘section’. you should keep the same name
$query['sections']Try this