[eluser]xtremer360[/eluser]
If you notice in the bottom var dump you notice how both of the objects have a news article id of 1 which is the article your viewing which is right. Now the tags associated with it is tag id 1 and tag id of 2. So if you look above those are all the post tags in the database.
I need it to take those two post tag ids of 1 and 2 and scroll through the top object and have the post tag with an id of 1 and 2 be checked so according to this the checkbox of Kid Wonder and Oriel should both be checked. I tried the in_array but couldn't find a working solution.
Code:
news_article_post_tags
array(3) {
[0]=>
object(stdClass)#33 (2) {
["news_article_post_tag_id"]=>
string(1) "1"
["news_article_post_tag_name"]=>
string(10) "Kid Wonder"
}
[1]=>
object(stdClass)#34 (2) {
["news_article_post_tag_id"]=>
string(1) "2"
["news_article_post_tag_name"]=>
string(5) "Oriel"
}
[2]=>
object(stdClass)#35 (2) {
["news_article_post_tag_id"]=>
string(1) "3"
["news_article_post_tag_name"]=>
string(11) "Ryu Satoshi"
}
}
news article index post tags data
array(2) {
[0]=>
object(stdClass)#37 (2) {
["news_article_id"]=>
string(1) "1"
["news_articles_post_tag_id"]=>
string(1) "1"
}
[1]=>
object(stdClass)#38 (2) {
["news_article_id"]=>
string(1) "1"
["news_articles_post_tag_id"]=>
string(1) "2"
}
}
Code:
<?php
foreach ($news_article_post_tags as $news_article_post_tag)
{
if (in_array($news_article_post_tag->news_article_post_tag_id, $news_articles_index_post_tags_data))
{
$checked_value = 'checked';
}
else
{
$checked_value = '';
}
$data = array('name' => 'news_article_post_tags', 'id' => $news_article_post_tag->news_article_post_tag_id, 'checked' => $checked_value);
echo form_label(form_checkbox($data).$news_article_post_tag->news_article_post_tag_name);
}
?>