Jump to content

How Would I..?


Joshua F

Recommended Posts

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?

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.