Joshua F Posted November 7, 2010 Share Posted November 7, 2010 How would I make a system that would send notifications to all registered members on my site? My site uses a database to store the user's info(Obviously), and each one has a user ID(Obviously), how would i make a script that gets all of the ID from the database, and make it send a message to everyone? Quote Link to comment Share on other sites More sharing options...
MSUK1 Posted November 7, 2010 Share Posted November 7, 2010 use the php mail() function to send the message, and use a SQL query to select the email addresses of the users so.. $sql="SELECT email FROM $tbl_name;"; then set the sql query as a variable $emails, and execute the mail funciton sorry its not ellaborate, laptops bat 6% wantd to atleast explain this Quote Link to comment Share on other sites More sharing options...
phpSensei Posted November 7, 2010 Share Posted November 7, 2010 What kind of notification system are you willing to set up? Easiest possible way is through EMAIL Smtp just by running a php script which does a bulk email to user's by grabbing the user's email from the database. Possible option 2. Create a INBOX or NOTIFICATION section in your user's profile page or however you have it set up. Then you have to create the database for the notifications and to the user the notification is assigned to. Its no different then making a simple email system... its all about the database... Quote Link to comment Share on other sites More sharing options...
Joshua F Posted November 7, 2010 Author Share Posted November 7, 2010 use the php mail() function to send the message, and use a SQL query to select the email addresses of the users so.. $sql="SELECT email FROM $tbl_name;"; then set the sql query as a variable $emails, and execute the mail funciton sorry its not ellaborate, laptops bat 6% wantd to atleast explain this Not wanting to make it use email. What kind of notification system are you willing to set up? Easiest possible way is through EMAIL Smtp just by running a php script which does a bulk email to user's by grabbing the user's email from the database. Possible option 2. Create a INBOX or NOTIFICATION section in your user's profile page or however you have it set up. Then you have to create the database for the notifications and to the user the notification is assigned to. Its no different then making a simple email system... its all about the database... Already have notifications system, and everything you just said. It loads the notification by a type called userid. Quote Link to comment Share on other sites More sharing options...
MSUK1 Posted November 7, 2010 Share Posted November 7, 2010 Ok so best to create a notification system as mentioned above, use databases to store the notification and you could add a New part to your current code "one new message" and wen they read it it marks a read, in database 0s and 1s would do that Quote Link to comment Share on other sites More sharing options...
Joshua F Posted November 7, 2010 Author Share Posted November 7, 2010 Also, want to point this out. I already have the notification system and everything, I just need a way to make a script get all of the Id's out of the table `users` and sends the message with their ID. Quote Link to comment Share on other sites More sharing options...
MSUK1 Posted November 7, 2010 Share Posted November 7, 2010 Sends message to were? You have notifications correct me if I'm wrong they are your internal messages, and you don't want to use emails as an external message (internal as in on your site an outside your site) Quote Link to comment Share on other sites More sharing options...
Joshua F Posted November 7, 2010 Author Share Posted November 7, 2010 Ok so best to create a notification system as mentioned above, use databases to store the notification and you could add a New part to your current code "one new message" and wen they read it it marks a read, in database 0s and 1s would do that Here is the structure of my notification database CREATE TABLE IF NOT EXISTS `notifications_1` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, `ipaddress` varchar(250) NOT NULL DEFAULT '127.0.0.1', `read` int(20) NOT NULL DEFAULT '0', `closed` int(20) NOT NULL DEFAULT '0', `senderid` int(5) NOT NULL, `recieverid` int(5) NOT NULL, `sent` datetime DEFAULT NULL, `title` varchar(250) NOT NULL DEFAULT 'Regarding Your Account', `text` text NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=0 ; I'll explain how it works. id: This is just used for viewing the notification(EG. view.php?id=1) ipaddress: IP Address of the sender read: This updates to 1 once the user read it. closed: This updates to 1 once the user replies, or an admin closes it. senderid: The user id of the sender recieverid: The user id of the reciever sent: Date it was sent title: Just the title of it text: The content Here's how it works. User with the id of 1 send something to the user with the id of 2. So senderid is 1, and recieverid is 2. Quote Link to comment Share on other sites More sharing options...
phpSensei Posted November 7, 2010 Share Posted November 7, 2010 Again OP, Its all how you setup your database... how the script checks for new notifications and such.... Example Id user_id from_user title message message_read place the user ids in to an array ($user_id_array = array(user1,user2,3,4,5,6,7) <?php for($i=0; $i<=count($user_id_array); $i++){ mysql_query("INSERT INTO notification ('user_id','title','...') VALUES ('".$user_id[$i]."','asdsad','sadsad')"); } ?> gonna some errors in that screen, just to lazy to fix it now lets say user 1 goes to his notification page, then get all the messages with user_id = 1 Quote Link to comment Share on other sites More sharing options...
Joshua F Posted November 7, 2010 Author Share Posted November 7, 2010 Again OP, Its all how you setup your database... how the script checks for new notifications and such.... Example Id user_id from_user title message message_read place the user ids in to an array ($user_id_array = array(user1,user2,3,4,5,6,7) <?php for($i=0; $i<=count($user_id_array); $i++){ mysql_query("INSERT INTO notification ('user_id','title','...') VALUES ('".$user_id[$i]."','asdsad','sadsad')"); } ?> gonna some errors in that screen, just to lazy to fix it now lets say user 1 goes to his notification page, then get all the messages with user_id = 1 Thanks, I'll try it out later. Quote Link to comment 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.