简体   繁体   中英

Table with INNER JOIN, how to update

I have two tables for Categories and Subcategories.
Categories has (categorie_id and categories_name) columns;
SubCategories has (subCategorie_id, subCategorie_display, categorie_id, subCategory_name) columns.
I did a LEFT OUTER JOIN query to obtain all the records in Subcategories, and match the ones that have the same categorie_id . Here is my code:

("SELECT subCategorie_id, subCategorie_name, subCategorie_display, categories.categorie_name, subCategories.categorie_id 
  FROM subCategories 
  LEFT OUTER JOIN categories ON categories.categorie_id = subCategories.categorie_id");

Now i have a form in which the content is displayed. I wan't to be able to edit that form, and update the table with the updated content. This is my query:

("UPDATE subCategories 
  LEFT OUTER JOIN categories 
  ON categories.categorie_id = subCategories.categorie_id
  SET subCategorie_display='$display', subCategories.categorie_id='$catID',subCategorie_name='$name' 
  WHERE subCategorie_id='$id'")

What i get from this query is a new row with the correct content, but the one i wanted to edit, stays like it was.

Here is my HTML:

<select id="choosecat" name="choosecat" required>
     <?php foreach($categoriesAll as $categorie) { 
         if($subcat->categorie_id == $categorie->categorie_id) { ?>
            <option selected value="<?php echo $categorie->categorie_id; ?>"><?php echo $categorie->categorie_name; ?></option>
         <?php } else { ?>
            <option value="<?php echo $categorie->categorie_id; ?>"><?php echo $categorie->categorie_name; ?></option>
      <?php } }?> 
</select>

How can i fix this? Already searched other answers but none worked.

Ok, so i found the bug. The problem was in my form action, the link was calling a wrong id.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM