I have a bit difficulty to explain this question in a simple way, so explanation will be long. User can vote if comment is useful or not (simple yes or no), and when he do this, his vote is send into data base -> table 'user_vote'.
Table user_vote have two columns - user_id and container. Every user have only one row in this table. When he cast new vote, field container is updated. For example, user vote on a comment with id 205 and he voted yes, and on a comment with id 300 he voted no. Table user_vote will look like this:
user_id->111;
container->205-yes,300-no
This is working fine, until this code here, where I need to check if user had voted on particular comment. Code here is working partially - problem is following:
Is user had voted 3 time and if id of the comment matches $split[0] it will one time write $text and it will produce 2 set of buttons, and if id of the comment is not matched it will produce 3 set of buttons (part after elseif is working correctly).
What am I doing wrong and how can I write code in correct way?
<div class="zuta_strana_komentar_korisno" data-id="<?php echo $cmm['id_comment'] ?>">
<?php if(isset($glas) && !empty($glas)) :
$br = explode(',', $glas->container);
foreach($br as $br) :
$split = explode('-', $br);
if($split[0] == $cmm['id_comment']) : ?>
<?php
if($split[1] == 'yes') :
$text = 'koristan.';
else :
$text = 'nekoristan.';
endif;
?>
<p>Ovaj komentar vam je bio <?php echo $text ?></p>
<?php else :?>
<p>Da li vam je ovaj komentar bio od pomoći?</p>
<button role="yes">Da</button><button role="no">Ne</button>
<?php
endif;
endforeach;
elseif($this->session->userdata('is_logged_in') == TRUE && empty($glas)) : ?>
<p>Da li vam je ovaj komentar bio od pomoći?</p>
<button role="yes">Da</button><button role="no">Ne</button>
<?php endif ?>
</div>
foreach($br as $br) :change this to somethingforeach($br as $br_value) :- then you'll also need to change all the $br to $br_value inside this loop.