Hello,
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 "";
}