i am have user options stored in database separated by comma and i have the full list of options from which user selected these options . i am trying to get the options user selected then separate it breaking each value after comma and then compare it with full options and make the users option checked out of all the options using a check box. and keep the rest of he options unchecked . but the problem is my results are getting repeated . this is my code
function
get_religion_pref($page,$user_id)
{
$getrow=mysql_query("select * from religion");
while($results=mysql_fetch_array($getrow))
{
$main_values=$results['religion'];
$query=mysql_query("select * from partner_prefrences where uid=$user_id");
$row=mysql_fetch_array($query);
$string =$row['religion'];
$string = preg_replace('/\.$/', '', $string); //Remove dot at end if exists
$array = explode(',', $string); //split string into array seperated by ', '
foreach($array as $value) //loop over values
{
?>
<li>
<label class="checkbox">
<input type="checkbox" value="<?php echo $main_values; ?>"
<?php if($main_values==$value){?> checked <?php } ?>><?php echo $main_values; ?>
</label>
</li>
<?php
}
}
}
?>