I have a problem with automatically checked values. Using a database, I display the values in a checkbox. Then from the database from another table I want to automatically select them. The data is in the list. I exploded it and checked.
<?php
require('../config.php');
$result = mysqli_query($con, "SELECT * FROM pk_skladnik") or die ( mysqli_error($con) );
while($row = mysqli_fetch_assoc($result)){
$cal = mysqli_query($con, "SELECT * FROM pk_pizza WHERE IdPizza = 1") or die ( mysqli_error($con) );
$sol = mysqli_fetch_array($cal);
$values = $sol['sklad'];
$array_of_values = explode(", ", $values);
?>
<div class="form-check">
<?php
foreach ($array_of_values as $key){
$xxx = ($key == $row['skladnik'] ? "checked" : "");
?>
<input class="form-check-input" type="checkbox" value="<?= $row['skladnik']; ?>" <?= $xxx; ?>>
<?php } ?>
<label class="form-check-label">
<?= $row['skladnik']; ?>
</label>
</div>
<?php } ?>
The current result is, for example, three rows of columns with one value checked in each of them. I want to check these 3 values in one column.
Aucun commentaire:
Enregistrer un commentaire