gpt4 book ai didi

php - 更新 mysql 中的逗号值

转载 作者:行者123 更新时间:2023-11-30 23:39:33 26 4
gpt4 key购买 nike

我在 mysql 中有一个产品表,其中一个字段(属性字段)包含逗号值,如 attibutes_1、attibutes_2 等。在我的表单中,我的产品有一个复选框 foreach 属性,像这样的 html

<input type="checkbox" value="attributes_1" name="attributes[$id][]">
<input type="checkbox" value="attributes_2" name="attributes[$id][]">

我的问题是,...我该如何更新这些属性值?如果用 implode 试试这个

  $coma_values = implode(',',$_POST['attributes'][$id]);

并将其更新到表格中,但有时效果不佳。请帮助我寻求更好的解决方案

最佳答案

您需要一个单独的属性表,然后用一个 id 字段链接这两个表。

table 1:
id, somedata1, somedata2

table 2:
id, table1_id, attribute_name, attribute_value

或类似的东西。 table1_id 将具有与第一个表中匹配的 id 关联的值。这样你就可以在记录和属性之间建立一对多的关系。这将允许您使用带有 JOIN 的查询从一个结果集中的两个表中提取数据。您永远不应在一个字段中存储逗号分隔值。

关于php - 更新 mysql 中的逗号值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4636963/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com