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 8232537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:51:57+00:00 2026-06-07T17:51:57+00:00

I need help suppressing a warning that I am getting from a foreach() Warning:

  • 0

I need help suppressing a warning that I am getting from a foreach()

Warning: Invalid argument supplied for foreach() in 
/sitename/pages/admin/questions/index.php

I am getting the result I want. All I need is to remove the warning…

This is my code:

for($i = 1; $i <= $RESULTS_count; $i++){

$rawResult = $wpdb->get_row(
                $wpdb->prepare("SELECT * FROM ".WPSQT_TABLE_RESULTS." WHERE id = $i"),ARRAY_A);

$rawResult['sections'] = unserialize($rawResult['sections']);

     foreach($rawResult['sections'] as $result_sections){
         if($result_sections['answers'][1]['mark'] == 'correct') $correct_answer++;
    }
}
echo $correct_answer/$RESULTS_count;

If I take the code out of the FOR loop and replace WHERE id = $i with WHERE id = 1 it will work… Could the problem be FOREACH does not like being in FOR loop?

What do you think I should do?

EDIT: I think the warning I was getting was caused by the fact that I deleted the result with ID 2, so when loop over the table rows one of them is empty and that is way I am getting the 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-07T17:51:59+00:00Added an answer on June 7, 2026 at 5:51 pm

    You should ensure the data is an array first or typecast it to an array.

    Is array:

        if (is_array($rawResult['sections'])) {
            foreach ($rawResult['sections'] as $result_sections) {
                if ($result_sections['answers'][1]['mark'] == 'correct')
                    $correct_answer++;
            }
        }
    

    Typecast:

        foreach ( (array) $rawResult['sections'] as $result_sections) {
            if ($result_sections['answers'][1]['mark'] == 'correct')
                $correct_answer++;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Need help with a query that I wrote: I have three tables Company id
Need help getting Ember-Data working with Zend Rest. At first, I'm familiar with Zend
Need help on these 2 questions: If i am tracking a virtual pageview for
Need help writing a script downloads data from google insight using c# this is
Need help. I have Graph API code that uses an auth token with offline
need help... the getting input form: <select name=age> <option value=25-30>25-30</option> <option value=31-40>31-40</option> <option value=41-50>41-50</option>
Need help with an error message that I just can't figure out. I am
Need help for that. I have a tabbar with 2 views, A and B
Need help with PHP/MySql. Need to select all the records from 'today'. My table
Need help with my simple PHP menu. I'd like to have something like that:

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.