heldenbrau Posted September 11, 2009 Share Posted September 11, 2009 I get this error Warning: Invalid argument supplied for foreach() in /home/kangerc1/public_html/postonsuper.php on line 112for the following code: $sortedvotes = sort($votecounter); $smallcount=1; foreach ($sortedvotes as $c){ $sql="INSERT IF NOT EXISTS INTO supersum$casenum (field, votes) VALUES ($c,1)"; if ($mysqli->query($sql)===true){ }else{ die("could not insert vote into supersum" . $mysqli->error); } if ($c==$foreachcounter){ $smallcount++; $sql="UPDATE supersum$casenum votes='$smallcount'";; if ($mysqli->query($sql)===true){ }else{ die("could not insert vote into supersum" . $mysqli->error); } }else{ $smallcount=1; } $foreachcount=$c; } Why am I getting this error? Quote Link to comment https://forums.phpfreaks.com/topic/173944-solved-invalid-argument-supplied-for-foreach/ Share on other sites More sharing options...
Alex Posted September 11, 2009 Share Posted September 11, 2009 $sortedvotes isn't an array. Quote Link to comment https://forums.phpfreaks.com/topic/173944-solved-invalid-argument-supplied-for-foreach/#findComment-916926 Share on other sites More sharing options...
ToonMariner Posted September 11, 2009 Share Posted September 11, 2009 sort does NOT return an array - it returns true or false... <?php sort($votecounter); $smallcount=1; foreach ($votecounter as $c){ $sql="INSERT IF NOT EXISTS INTO supersum$casenum (field, votes) VALUES ($c,1)"; if ($mysqli->query($sql)===true){ }else{ die("could not insert vote into supersum" . $mysqli->error); } if ($c==$foreachcounter){ $smallcount++; $sql="UPDATE supersum$casenum votes='$smallcount'";; if ($mysqli->query($sql)===true){ }else{ die("could not insert vote into supersum" . $mysqli->error); } }else{ $smallcount=1; } $foreachcount=$c; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/173944-solved-invalid-argument-supplied-for-foreach/#findComment-916927 Share on other sites More sharing options...
heldenbrau Posted September 11, 2009 Author Share Posted September 11, 2009 Thanks a lot, that sorted it. Quote Link to comment https://forums.phpfreaks.com/topic/173944-solved-invalid-argument-supplied-for-foreach/#findComment-916969 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.