I'm working on a notification system for a website and here's the basic idea;
I have a table Notifications
where I have columns
notif_msg notif_url receiver_s
where receiver_s
will have multiple commas separated values. However, I learned this is not so good idea and was advised to have a different table to store receivers. creating a one to many relationships as specified here. However, I am baffled on few things as I am no guru in MySQL.
here's how my create statement looks like following the example from the link above;
create table `notifications` ( `id` int unsigned not null auto_increment,`notif_msg` varchar(500) not null,`notif_url` varchar(100) not null, primary key(`id`));
create table `notifications_target` ( `id` int unsigned not null auto_increment, `notification_id` int unsigned not null, `receiver` varchar(25) not null, index pn_user_index(`notification_id`), foreign key (`notification_id`) references notifications(`id`) on delete cascade,primary key(`id`));
I need to know a few things;
- what function does the
index
serve in there? - from here, how do I insert value into
notif_msg
,notif_url
innotifications
table and multiple receivers intoreceivers
column innotification_target
referencing a particular row innotifications
table? - How do I get values back from
notifications
table and their correspondingreceiver
innotification_target
table?
here's how I intend to get notifications
relating to a specific user and all users at the same time before now;
SELECT
notif_msg
,notif_url
FROMnotifications
WHERE receiver_s= somename AND WHERE receiver_s=' '
how do I do this now that I have different tables for receivers?