I do not know how to explain, but I will try. I have a table "users", it contains all the information about users, there is a table "pm" - messages, how to make it so that when sending a message it goes to everyone at once? (When sending I use:

INSERT INTO pm (to,author,time,title,content) VALUES ($to,$author,$sendtime,$title,$message); 

For example, it is not convenient for me to crawl into the code every time and change the number of users ... Can you help? I want to send messages to all users by clicking on the "send" button, that is, one message was repeated several times ( depending on the number of users ) and changed only by the recipient. Example:

 INSERT INTO pm (to,author,time,title,content) VALUES ('92','1','21:18','title','message'); 

and, if the 92nd user is not the last, then the message is sent to 93, 94, and so on ...
Most likely I explained it incomprehensibly, but I can’t do it differently: (Preferably ready code :)

  • "Preferably ready code" - well, it was necessary to spoil everything at the end! - Igor
  • @Igor explanation is hardly enough for me ... Therefore, I ask for the ready code, alas ... :( - ya.ymer
  • @Igor he was close))) - Vasily Barbashev

1 answer 1

Make a selection of user IDs from the users table and insert them along with the other required fields (in one request, no additional code in php is needed):

 INSERT INTO pm (to,author,time,title,content) SELECT user_id,$author,$sendtime,$title,$message FROM users