I am trying to delete every follower from an array using PHP. However I am receiving the error :
Warning: Invalid argument supplied for foreach() in /home/nucleusi/public_html/maxkdevelopment.co.uk/SocialPic/socialPic.php
Please can you tell me where I am going wrong?
$arg = mysql_query("SELECT `followerUserID` FROM Following
WHERE `followingUserID` = '$id'") or die("1. " . mysql_error());
$array = mysql_fetch_array($arg);
foreach($array['followerUserID'] as $accID) {
mysql_query("UPDATE Accounts SET `Following Count` = (`Following Count`-1)
WHERE `id` = '$accID'") or die("2. " . mysql_error());
}
$arg = mysql_query("SELECT `followingUserID` FROM Following
WHERE `followerUserID` = '$id'") or die("3. " . mysql_error());
$array = mysql_fetch_array($arg);
foreach($array['followingUserID'] as $accID) {
mysql_query("UPDATE Accounts SET `Followed Count` = (`Followed Count`-1)
WHERE `id` = '$accID'") or die("4. " . mysql_error());
}
MySQL will not return arrays in a field, indexing an array retrieved from a query will return a single field, and
foreach()expects an array. What you have written cannot work. Use awhile()loop to iterate through the query results as one would normally do.