I want to populate check boxes from a table and mark them checked if they have records on another table.
I have two queries as shown below.
$hizmetler = "SELECT * ";
$hizmetler .= "FROM hizmetler";
$sonuc = mysqli_query($conn,$hizmetler);
and
$id= $_GET['id'];
$query_hizmet = "SELECT * FROM firmahizmet INNER JOIN hizmetler ON firmahizmet.hizmetID=hizmetler.hizmetID ";
$query_hizmet .= "WHERE firmahizmet.firmaID = $id";
$myresult = mysqli_query($conn, $query_hizmet);
I am trying to populate checkboxes with 1st query and add checked with 2nd query.
while ($row0 = mysqli_fetch_assoc($myresult)){
while($row2 = mysqli_fetch_assoc($sonuc)){ ?>
<label for="chkbox"></label>
<input id="chkbox" type="checkbox" name="<?php echo $row2["hizmetCSS"];?>" value="<?php echo $row2["hizmetCSS"];?>" <?php echo ($row0['hizmetCSS']==1 ? 'checked' : '');?> /><?php echo $row2["hizmetAdi"];
}
}
But I think I am missing a huge point :D Tried to create a function and seek if myresult has overlapping values in sonuc, if yes I'd add checked but failed as well.
I inspected a similar post with an good idea of
' . (in_array($role_name, $user_in_role) ? ' checked="checked"' : '') . '
but if the record does not have any row on firmahizmet table I get the following error;
in_array() expects parameter 2 to be array
Any directions?