onthespot Posted September 2, 2009 Share Posted September 2, 2009 Hey guys, I have a question. I have two tables. User and Messages. What SQL would I need to take all users from the user tables and message them all? Like the messages have to_user, and that needs to be every user from the user table. Am just trying to create a mass PM function. Thankyou Quote Link to comment https://forums.phpfreaks.com/topic/172824-insert-into-all/ Share on other sites More sharing options...
Pickle Posted September 2, 2009 Share Posted September 2, 2009 are you saying that you want to take the users from the user table and message them all the same message? or does the message table hold a message unique for each user in the user table? Quote Link to comment https://forums.phpfreaks.com/topic/172824-insert-into-all/#findComment-910884 Share on other sites More sharing options...
onthespot Posted September 2, 2009 Author Share Posted September 2, 2009 Sorry yes message them the same message. Just a message to all the user basically. The same message as a MASS pm Quote Link to comment https://forums.phpfreaks.com/topic/172824-insert-into-all/#findComment-910897 Share on other sites More sharing options...
gevans Posted September 2, 2009 Share Posted September 2, 2009 I'd go about it this way... $query = "SELECT `user_id` FROM `User`"; $result = mysql_query($query); while($data = mysql_fetch_assoc($result)) { mysql_query("INSERT INTO `Messages` VALUES('{$data['user_id']}', 'the message', 'other stuff')"); } You will need to play with this, but it's generally right. Quote Link to comment https://forums.phpfreaks.com/topic/172824-insert-into-all/#findComment-910908 Share on other sites More sharing options...
onthespot Posted September 2, 2009 Author Share Posted September 2, 2009 Yeah thats what i was expecting, something like that. I will play around with the values and that should work, thankyou Quote Link to comment https://forums.phpfreaks.com/topic/172824-insert-into-all/#findComment-910912 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.