gpt4 book ai didi

php - jQuery Sortable - 按 ID 查看顺序

转载 作者:太空宇宙 更新时间:2023-11-03 11:07:11 26 4
gpt4 key购买 nike

我知道目前已经有关于将 jQuery 可排序列表保存到数据库的问题。如何查询我的 2 个表,获取“order”字符串,然后以正确的顺序显示可排序列表。我的表是:

Table name: clothing_category
id name order
-----------------------------------------
5 Headwear 29,22,26

和:

 Table name: clothing_type
id name clothing_id (relational with to 'clothing_category')
-----------------------------------------
22 Hat 5
26 Beanie 5
29 Visor 5

因此,看到头饰的“顺序”如何存储为“29,22,26”,我希望 HTML 输出如下:

<ul id="sortable">
<li id="29">Visor</li>
<li id="22">Hat</li>
<li id="26">Beanie</li>
</ul>

如何像上面那样显示?我存储订单的方法是执行此操作的好方法吗?

最佳答案

我会在 clothing_type 表中添加一个 Order 或 Sequence 列,其中包含从 1 到 3 的数字(在本例中)。查询表时,按序列字段排序。

要更新,请使用如下伪代码:

$orderedID = array(29,22,26);
foreach($orderedID as $i => $id) {
$query = 'UPDATE `clothing_type` SET `sequence`=' . $i . ' WHERE `id`=' . intval($id);
}

关于php - jQuery Sortable - 按 ID 查看顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11198440/

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