Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8466303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:18:11+00:00 2026-06-10T15:18:11+00:00

Below is my model, it works correctly. Right now it is returning false because

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T15:18:13+00:00Added an answer on June 10, 2026 at 3:18 pm

    It is not ‘section’. you should keep the same name$query['sections']

    Try this

     $Student_ID = $session_data['Student_ID'];
     $query['sections']=  $this->grades_model->get_schedule($Student_ID);
    
    
     if ($query['sections'] == false)
     {
      echo "error";
     }
     else
     {
      foreach($query['sections'] as $row)
      {
       do stuff:
      }
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

my Devise Recaptcha isn't working correctly because I can skip right over it and
I am testing this simple code below and it works... $(document).ready( function() { $('.show-modal').click(
I am using Polymorphic Models . Simple Question: My code below works without using
Below all my code, * Model * Below is Model code, public class MyViewModel
Based on the data model below And based on user input I create a
I have three model classes that look as below: class Model(models.Model): model = models.CharField(max_length=20,
I have this edmx model (see below) and I would like to add an
I have my entities as below. My data model enforces below and I cannot
Below I call the same methods in author and w5 model objects. But one
For the below models: class Customer(models.Model): id = models.IntegerField(primary_key=True) class OrderA(models.Model): name = models.CharField(max_length=20)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.