I am trying to echo the following function:
[php]
function LikeCounter($names)
{
$likes = 0;
$count = strlen($names);
echo($count . “
”);
echo($names);
for ($i = 0; $i == $count; $i++)
{
echo(‘Works!’);
if ($names{$i} == ‘,’)
{
$likes += 1;
}
}
return $likes;
}
[/php]
$names is a string containing usernames separated by a comma.
When I register a new user to my website their profile is created on the database with a “Welcome!” comment.
When I go to their profile, the comment is displayed and above this comment, “0” is echoed since $names = “”. After this is the message “Works!” is displayed and since there are no commas in $name, the returned value is 0. Everything seems to be working fine.
When I “like” this comment, $names now contains the value "username, " and if I like it again it will be username, username, " etc.
The problem is that after I’ve “liked” a comment, the message “Works!” is no longer displayed and the returned value is still 0. It seems like the function ignores the for loop every time I call the function except for the first time.
When new comments are added to a profile, the same thing happens; the for loop only works the first time when $names = “”.
Any ideas?
Thanks in advance