1
Guys, I’m banging my head here with this... I have two tables in the bank, one corresponds to the department and another corresponds to the checkbox registered for that department, the problem is, how to bring these checkbox marked, for example, I need to validate them in the display, as "checked", that inside the while, but they are two different tables... I even managed to get halfway through, but it displays only one result. Follow below table and code, if anyone can give a help, I really appreciate.
$sql = "SELECT * FROM departamentos";
$rs = mysqli_query($conn, $sql);
while($departamento = mysqli_fetch_array($rs)){
$sql2 = "SELECT DISTINCT id_departamento FROM checkbox WHERE tipo='1' AND id_galeria_artigo='$id'";
$rs2 = mysqli_query($conn, $sql2);
$checkbox = mysqli_fetch_array($rs2)
?>
<label class="btn <?php if($departamento['id'] == $checkbox['id_departamento']) { echo 'active';}?>" style="margin:5px">
<input type="checkbox" name="check[]" value="<?php echo $departamento['id']?>" > <?php echo $departamento['title']?>
</label>
<?php
}
?>
This is the table "checkbox":
Department table:
Galeria Table:
can post the other table? and the expected result?
– user60252
The second SELECT always returns the same result within while
– user60252
So Leo, the other table would be just the department, in this case the client registers a gallery, and this gallery needs to appear in the respective selected departments, these departments are selected via checkbox, and save in the table "checkbox", when the user will edit this gallery in the panel, I need to display the checkbox for the respective departments, and I need to check whether this checkbox was selected or not, to mark as checked, understand?
– Guga_Opala
I understand, but without this table I cannot run the script to perform tests.
– user60252
Got it... I top the two tables, the department, and the gallery, I believe is not so relevant, because it only takes the id of the selected gallery...
– Guga_Opala
I drove here and returned this https://i.stack.Imgur.com/Bntfv.png
– user60252
is because of the "check" in the input, I edited up there and took it, what makes the asset validation or is not the if above, if that department is active, it prints the "active"
– Guga_Opala
That $id comes from where?
– user60252
he took from the gallery, inside this gallery I have the departments to be selected.
– Guga_Opala
I’m not seeing what would be the problem, the image I showed you is not the expected result? What would be the expected result?
– user60252