ArizonaJohn Posted June 18, 2009 Share Posted June 18, 2009 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 More sharing options...
ArizonaJohn Posted June 18, 2009 Author Share Posted June 18, 2009 Someone told me to add $table_list = array(); , and it solved the problem: $table_list = array(); while(list($table)= mysql_fetch_row($result)) { Link to comment https://forums.phpfreaks.com/topic/162730-solved-if-statement-error/#findComment-858769 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.