[eluser]ibnclaudius[/eluser]
I'm trying to do a 'Like' system like Facebook.
My problem is how to output it, here are example of all possible outputs.
You like this.
You and Derp Like this.
You, Derp and Derpina like this.
You, Derp, Derpina and 999 others like this.
Derp like this.
Derp and Derpina Like this.
Derp, Derpina and Derps like this.
Derp, Derpina, Derps and 999 others like this.
This what I did so far, I came here to the forum because I'm pretty sure there's a much better solution:
$count_school_update_likes = count all the likes.
$count_school_update_liked = return 1 if the current user like.
$get_school_update_likes = get all the likes (except the current user).
Code:
if ($count_school_update_likes == '1')
{
if ($count_school_update_liked == '1')
{
echo 'You';
}
else
{
foreach ($get_school_update_likes->result_array() as $liker)
{
echo '<a href="#">' . $liker['user_name'] . '</a>';
}
}
}
else
{
if ($count_school_update_likes == '2')
{
if ($count_school_update_liked == '1')
{
echo 'VocĂȘ e ';
foreach ($get_school_update_likes->result_array() as $liker)
{
echo '<a href="#">' . $liker['user_name'] . '</a>';
}
}
else
{
foreach ($get_school_update_likes->result_array() as $liker)
{
echo '<a href="#">' . $liker['user_name'] . '</a>';
}
}
}
elseif ($count_school_update_likes == '3')
{
//...
}
}
echo ' like this';