Jump to content

[SOLVED] If statement error


ArizonaJohn

Recommended Posts

Hello,

 

For the code below, I am trying to use an 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 "";
}

Link to comment
https://forums.phpfreaks.com/topic/162730-solved-if-statement-error/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.