【发布时间】:2017-10-26 21:29:50
【问题描述】:
下面的query 将消息注释插入到表格中:
mysqli_query($con,"INSERT INTO msgs VALUES ('', '$user_id', '$username', '$text','$time', )");
当插入msgs 表时,我想实现一个通知系统,其中当$text 变量包含类似@mention 的字符串时(插入通知类型为mention 的通知表)
我用这个正则表达式来检查text 变量是否有@:
preg_match_all('/(@\w+)/', $msg, $matches);
foreach ($matches[0] as $username)
通知插入查询:
mysqli_query($con, "INSERT INTO notifications VALUES ('', '$trigger_userid', '$trigger_username','$msg_trigger_recvr_id', '$recipient_uname', '$action', '$status', '$time', now() ) ");
解释:
第一个空 ' ' 包含自动递增的 id 列。
$trigger_userid 是提及用户的id
$trigger_username 是提及用户的username
$msg_trigger_recvr_id 我希望这是 msg 表中该特定消息注释的 id。
$recipient_uname 这将是正则表达式中的@mention。如果$text 包含多个提及(@mention1 和@mention2),我想将每个提及插入新行
$action 被提及,$staus 默认为unread。
问题是我无法插入 foreach 的所有值,它只插入最后一个 mention 在有多个 mentions 的情况下,我想在新行中插入值。
请帮忙。
【问题讨论】:
-
我目前没有看到任何问题或解释什么不起作用。请编辑问题以明确说明您需要什么帮助
-
对于 auto_increment 你不需要像这样给
' '..那会自动插入 -
@SamiKuhmonen 问题已更新,谢谢。
-
@chris85 谢谢,这是个错误。我已更新问题以说明问题。
-
查看 LAST_INSERT_ID(和/或其 PHP 中的配套函数)