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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:45:44+00:00 2026-05-11T20:45:44+00:00

For the code below, I am trying to use the IF statement if(mysql_num_rows($resA)>0) to

  • 0

For the code below, I am trying to use the IF statement

if(mysql_num_rows($resA)>0)

to avoid running the foreach loop if $entry is not in the “site” column in any table in my database. However, if $entry does not exist in the “site” column in any table in my database, I get the error message “Warning: Invalid argument supplied for foreach()”. Any idea why it is doing that?

Thanks in advance,

John

$result = mysql_query("SHOW TABLES FROM feather") 
or die(mysql_error()); 

while(list($table)= mysql_fetch_row($result))
{
  $sqlA = "SELECT COUNT(*) FROM `$table` WHERE `site` LIKE '$entry'";

  $resA = mysql_query($sqlA) or die("$sqlA:".mysql_error());
  list($isThere) = mysql_fetch_row($resA);
  $isThere = intval($isThere);
  if ($isThere)
  {
     $table_list[] = $table;
  }

}

if(mysql_num_rows($resA)>0){
foreach ($table_list as $table) { 
    $sql = "SELECT votes_up FROM `$table` WHERE `site` LIKE '$entry'"; 
    $sql1 = mysql_query($sql) or die("$sql:".mysql_error());
   while ($row = mysql_fetch_assoc($sql1)) {
       $votes[$table] = $row['votes_up'];
       $sum += $row['votes_up'];
   } 

}
}
else{
print "";
}
  • 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-05-11T20:45:44+00:00Added an answer on May 11, 2026 at 8:45 pm

    It’s a good idea to initialize variables:

    $table_list = array(); // <-- Initialize variable.
    while (list($table) = mysql_fetch_row($result)) {
        /* ... */
        $table_list[] = $table;
        /* ... */
    }
    
    if (mysql_num_rows($resA) > 0) {
        foreach ($table_list as $table) { 
            /* ... */
        }
    }
    

    You’re getting the error because no entries are added to $table_list which means the variable won’t exist when you run the foreach loop. Initialize it first to avoid this confusion.

    The reason no entries were added to $table_list is because the count of all tables fetched was zero.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 120k
  • Answers 120k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Hello,The code that you say is not working is legal… May 12, 2026 at 12:16 am
  • Editorial Team
    Editorial Team added an answer Any chance you are running on x64? On my x64… May 12, 2026 at 12:16 am
  • Editorial Team
    Editorial Team added an answer I managed to fix it myself by converting the Login… May 12, 2026 at 12:16 am

Related Questions

For the code below, I am trying to use the IF statement if(mysql_num_rows($resA)>0) to
I am trying to use the following code to write out all processes started
I have an existing PDF and I can use FdFWriter to input to text
I am trying to use Generic Types in Windows.Resources section in XAML code. To
I am trying to use Validation in WPF. I created a NotNullOrEmptyValidationRule as shown

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.