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? 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. 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; } ?> 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. 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
Archived
This topic is now archived and is closed to further replies.