I've been twisting my head for days without getting what I want, so I'm writing here hoping to get some help. I have two tables (actually 3, but we'll leave the last one out here).
TABLE 1 NAME:
pakkliste_gjenstand
COLUMNS:
id
pakkliste_gjenstand
TABLE 2 NAME:
pakkliste_detalj
COLUMNS:
id
prosjekt_id
pakkliste_detalj_gjenstand_id
pakkliste_detalj_gjenstand
In the "pakkliste_gjenstand" table there are hundres of lines with items that I can select by checkboxes, and add to the "pakkliste_detalj" table. The id-field from the "pakkliste_gjenstand"-table is stored in the "pakkliste_detalj"-table as pakkliste_detalj_gjenstand_id
Then we get to what I want, namely to run a reverse to be able to update my "pakkiste_detalj"-table. I want to be able to loop through the entire "pakkliste_gjenstand"-table, and check off the lines that are already selected in "pakkliste_detalj"-table. I need to match the id-field in table 1 (pakkliste_gjenstand) with pakkliste_detalj_gjenstand_id in table 2 (pakkliste_detalj).
I use the following code to loop throug the "pakkliste_gjenstand"-table:
<?php
$do_search=mysqli_query($link, "SELECT * FROM pakkliste_gjenstand ORDER BY pakkliste_gjenstand ASC");
while ($row = mysqli_fetch_array($do_search))
{
$id=$row['id'];
$produkt=$row['pakkliste_gjenstand'];
?>
<input type="checkbox" name="check_list[]" value="<?php echo $id; ?>*<?php echo $produkt; ?>"> <?php echo $produkt; ?>
<br>
<?php
}
?>
Is it possible to do something with this so that I can have the items from "pakkliste_detalj" to be checked, but still show the rest of the lines as well?
I've searched the net, and tried different codes as LEFT JOIN, INNER JOIN and a lot other approaches without luck.
Could anyone help me? I don't want to use javascript ...
Aucun commentaire:
Enregistrer un commentaire