Can someone help me to solve this issue?
Below code i used in an edit page, and i want to compare the checkbox values and if it is matching make it as checked.
Example of my two array values
$CategoryDetails : Array ( [0] => 6 [1] => 1 )
$Category_data : Array ( [0] => 1 [1] => 3 [2] => 6 [3] => 2 [4] => 4 [5] => 7)
$Category_data
is am using to create checkbox and $CategoryDetails
is the selected values. So checkbox 1 & 3 should be checked, but below code giving me only one checked ie. checkbox3
I need to compare each value of array1 with array2.
<?php
$CategoryDetails = isset($category_list) ? $category_list : ' ';
$Category = dbSelectByWhere("Highlight_categories", "WHERE Highlight_cat_status=1", "Order By Highlight_Category_name");
$k = 0;
while ($Category_data = dbFetchArray($Category)) {
?>
<input type="checkbox" name="category[]" id="Category" value="<?php echo $Category_data['Highlight_category_id']; ?>" data-parsley-mincheck="1" required class="flat" <?php
if (isset($CategoryDetails) && ($CategoryDetails[$k] == $Category_data['Highlight_category_id'])) {
echo 'checked';
if ($k < (count($CategoryDetails) - 1)) {
$k++;
}
}
?>/> <?php echo $Category_data['Highlight_Category_name']; ?>
<?php } ?>
Aucun commentaire:
Enregistrer un commentaire