Reputation: 11
the query
below insert a message note into table:
mysqli_query($con,"INSERT INTO msgs VALUES ('', '$user_id', '$username', '$text','$time', )");
When inserting into msgs
table, i want to implement a notification system in which where by when the $text
variable contain string like @mention
(insert into notification table with notification type mention
)
I'v this regular expression to check if text
variable has @
:
preg_match_all('/(@\w+)/', $msg, $matches);
foreach ($matches[0] as $username)
The notificaion insert query:
mysqli_query($con, "INSERT INTO notifications VALUES ('', '$trigger_userid', '$trigger_username','$msg_trigger_recvr_id', '$recipient_uname', '$action', '$status', '$time', now() ) ");
Explanation:
1st empty ' '
contains the id column that is auto incremented.
$trigger_userid
is the id
of the user that making the mention
$trigger_username
is the username
of the user that making the mention
$msg_trigger_recvr_id
i want this to be the id
of that particular message note in the msg table.
$recipient_uname
this will be the @mention
from the regular expression. In case $text
contain multiple mentions (@mention1
and @mention2
), i want to insert each in new row
$action
is mention and $staus
is unread
by default.
The problem is i cannot insert all values of foreach , it inserts only the last mention
in a case where there is multiple mentions
, i'll like to the values in new rows.
Pls, kindly help.
Upvotes: 0
Views: 823
Reputation: 66
MySQL does not permit insertion into multiple tables using a single INSERT statement, if that is what you need clarity upon. Further, please state what does not work with the above code.
Upvotes: 2