[英]Table with INNER JOIN, how to update
I have two tables for Categories and Subcategories.我有两个类别和子类别表。
Categories has (categorie_id and categories_name)
columns;类别有
(categorie_id and categories_name)
列;
SubCategories has (subCategorie_id, subCategorie_display, categorie_id, subCategory_name)
columns. (subCategorie_id, subCategorie_display, categorie_id, subCategory_name)
有(subCategorie_id, subCategorie_display, categorie_id, subCategory_name)
列。
I did a LEFT OUTER JOIN
query to obtain all the records in Subcategories, and match the ones that have the same categorie_id
.我做了一个
LEFT OUTER JOIN
查询来获取 Subcategories 中的所有记录,并匹配那些具有相同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:这是我的 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.
问题出在我的表单操作中,链接调用了错误的 ID。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.