I have some data on my database:
id_tag | tag
------------
1 | Dog
2 | Cat
3 | Buldog
4 | Persian Cat
Then i have a parameter:
$tag = "2, 4";
I want to show All of tags into checkbox. If the id_tag is equal the $tag parameter. I have a trials:
echo "<div class='btn-group' data-toggle='buttons'>";
$thetag = explode(", ", $tag);
$tagall = mysql_query("SELECT * FROM tags");
if(mysql_num_rows($tagall) > 0)
{
while($tagt = mysql_fetch_array($tagall))
{
foreach($thetag as $ttg)
{
if($tagt['id_tags'] == $ttg)
{
$aktiv = "active";
$ceked = "checked";
}
else
{
$aktiv = "";
$ceked = "";
}
}
echo "<label class='btn btn-primary {$aktiv}'><input type='checkbox' value='{$tagt['id_tags']}' autocomplete='off' {$ceked}> {$tagt['tag']}</label>";
}
}
echo "</div>";
The result is:
Dog | Cat | Buldog | Persian Cat
with Persian Cat active and checked.
The result i need is Cat and Persian Cat active and checked. Please help me...!