gpt4 book ai didi

PHP MySQL 从之前的结果中插入新行

转载 作者:行者123 更新时间:2023-12-02 04:40:36 25 4
gpt4 key购买 nike

我有一个事件站点,我正在尝试创建一个脚本,向所有参加的成员发送警报。这是通过从出勤表中选择所有成员并为每个结果记录添加一条消息来完成的。我目前拥有的代码无法正常工作。这是代码:

$get_attendance_sql = "SELECT attendee FROM attendance WHERE event = '$event_id'";
$get_attendance_res = mysqli_query($con, $get_attendance_sql);
while($row = mysqli_fetch_assoc($get_attendance_res)){
$event_memberid = $row["attendee"];
}

foreach($row)
{
$insert_membernote_sql = "INSERT INTO notes (id, recipient, type, subtype, link, date) VALUES('$id', '$event_memberid', 'cancel', 'event', '$event_id', '$time')";
$insert_membernote_res = mysqli_query($con, $insert_membernote_sql);
}

最佳答案

试试这段代码。

您需要删除 foreach 并将插入查询移动到 while 循环中。

$get_attendance_sql = "SELECT attendee FROM attendance WHERE event = '$event_id'";
$get_attendance_res = mysqli_query($con, $get_attendance_sql);
while($row = mysqli_fetch_assoc($get_attendance_res)){
$event_memberid = $row["attendee"];
$insert_membernote_sql = "INSERT INTO notes (id, recipient, type, subtype, link, date) VALUES('$id', '$event_memberid', 'cancel', 'event', '$event_id', '$time')";
$insert_membernote_res = mysqli_query($con, $insert_membernote_sql);
}

关于PHP MySQL 从之前的结果中插入新行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20920013/

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