gpt4 book ai didi

mysql - 从字段中删除特定数据而不完全覆盖

转载 作者:行者123 更新时间:2023-11-29 21:20:04 26 4
gpt4 key购买 nike

我的表格中有一个用于入围职位的字段。当用户将作业添加到候选列表时,它将添加以逗号分隔的 ID。

例如:“1,2,3,4,5”

假设客户从候选列表中删除了一个职位,我需要删除该字段中的值,而不删除其他 ID。

因此,如果我们删除 ID 4,我需要它来将字段值更新为:"1, 2, 3, 5"

要添加数据,我使用当前查询:

UPDATE users SET shortlist = concat(shortlist, '".$r['jobid'].",') WHERE uid='".$row['uid']."'

我假设会有一些与我上面所做的事情类似的事情来实现这一目标,但我无法弄清楚。

任何帮助将不胜感激。

最佳答案

由于您是在 PHP 中创建列表,因此您也可以使用 PHP 修改它。

$stmt = $pdo->prepare("SELECT shortlist FROM users WHERE uid = :uid");
$stmt->execute(array(':uid' => $uid));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$shortlist = explode($row['shortlist']);
$pos = array_search('4', $shortlist);
if ($pos !== false) {
unset($shortlist[$pos]);
$shortlist_str = implode($shortlist);
$stmt = $pdo->prepare("UPDATE users SET shortlist = :shortlist WHERE uid = :uid");
$stmt->execute(':uid' => $uid, ':shortlist' => $shortlist_str));
}

关于mysql - 从字段中删除特定数据而不完全覆盖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35760428/

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