在用逗号分隔的旧行旁边添加一个新值

时间:2017-03-24 11:24:46

标签: php mysql sql mysqli

我在列pushed_closed中的值为“ 09:51 ”。

我需要添加列pushed_closed,旁边是值' 09:51 ',值2,如:

09:51 09:54 (以逗号分隔)。

我的PHP代码:

$connection = db_connect();
        $username = $_SESSION['username'];
        $ora_terminare = '09:54';
        mysqli_begin_transaction($connection);
        $query = mysqli_query($connection, "UPDATE birouri SET closed_program = 'DA', pushed_closed = '$ora_terminare' WHERE username = '$username'");
        mysqli_commit($connection);

如何创建正确的Mysqli查询?

1 个答案:

答案 0 :(得分:0)

$connection = db_connect();
$username = $_SESSION['username'];
$ora_terminare = '09:54';
mysqli_begin_transaction($connection);
$query = mysqli_query($connection, "UPDATE birouri SET closed_program = 'DA', pushed_closed = concat(coalesce(pushed_closed, ''), ',', '$ora_terminare') WHERE username = '$username'");
mysqli_commit($connection);

与旧值相结合将为您提供。