How to make notification to group users with read/unread flag? - php

I am making a notification system so that when users in a group perform an action, it will notify all the other users in the group. I want the notification to be marked "read" or "unread" for each user of the group. With that, I can easily retreive any unread notification for a user and display it. I am think about creating a notification table that have the following fields.
+----------------------+
| notification |
+----------------------+
| id |
| userid |
| content |
| status (read/unread) |
| time |
+----------------------+
My question is:
Whether it is the correct way of making the system? As it means that when there is 1,000 users in a group, then I have to insert 1,000 rows to the table. If not, what is the better way of doing this?
If it is the way to do this, how can I write the php/mysql codes to do the looping of inserting the rows?
Thanks!

A better way of doing that would be to separate the notification from the user, by doing the following:
Table Notification
------------------
not_id
time content
Table User
----------
u_id
Table NotificationStatus
------------------------
id
u_id
not_id
bool read
That way you have to save each notification only one, what makes it easier to modify/edit notifications

Consider the following data structure:
Table: Events
----------------
event_id
user_id (foreign key to users table)
action_id (foreign key to actions table)
time_stamp
Table: Log
----------------
user_id (foreign key to users table)
event_id (foreign key to events table)
time_stamp
The logic should be that all events are considered unread by user X unless Log table contains the event_id for that user
Actions table may have many types of actions.
You will be able to count and notify all users how many other users have "recieved" the action by querying the log. etc'...

yes..u can do it in this manner..
example: suppose any user "PQP" (user_id=1) is adding a photo then u have to write ur notification query on success of photo adding query (u need to write write query for notification on code wherever u want that point as notification) so your notification table will got new entry as
id = 1
userid =1
content = "Photo Added By User PQP"
status = Unread
time = currenttime
so by this case whenever someone uploads a photo then notification table will got entry in it..

Related

Mark is_read in Notification system with Laravel 5

I have a site where users can post things like statuses, pictures, etc. I'm wan't to create a notification system similar to Facebook . Something that alerts the user of their friends recent activity. My problem is i'm not sure how I should structure my table. I'm following some advice from an older tutorial Tutorial for the db scheme, and doing something like this
id | user_id | subject | body | object_id | object_type | is_read | sent_at | created_at | updated_at
I know what to do for the majority of the code, or at least have a good idea, my problem and question is for the is_read column, should i create a separate table to store that information, if not then how can I mark a notification as is_read with the current setup.
I guess you want to have a "is read" for EVERY friend/user, this was a bit unclear. If this is the case your best bet (in my opinion) would be to create a new table, as you said, containing the post_id, and user_id. All you then have to do is to check is such a relationship exists, and if so, show a notification.

Like a post/comment just once, laravel

Information:
I have 2 tables(users for the users of the website and new_themes for themes/posts(whatever) created by the users.
!!!There is no relationship between these 2 tables.(A user can create a new post if he is logged in)
Tables:
Users:
1 id
2 name
3 email
4 password
New_themes:
1 id
2 title
3 text
4 upVotes
5 downVotes
6 TagName
What I want to do:
I created the feature that user can like the post(but he can like it unlimited number of times) but I want them to be able to like just once in a life time a post.
What I can't figure out is the idea/structure/logic of how to make it. I am thinking of creating a table . A "pivot" one for tables users and new_themes(many to many relationship in Laravel)
1 id_user
2 id_theme
Where the both of them have a composite primary key so they won't be any duplicate values, so if the user wants to vote once again the same post he won't because there can't be duplicate values.
Here is the problem:
If this is the solution, I have doubt and no idea on how to populate the pivot table when a user likes a theme. If this isn't the solution any advice or idea will be very helpful for me to finish my last feature of my wep app.
Thank you very much.
What I can't figure out is the idea/structure/logic of how to make it. I am thinking of creating a table . A "pivot" one for tables users and new_themes(many to many relationship in Laravel)
That's the way to go. So it would look like this:
+---------+----------+
| user_id | theme_id |
+---------+----------+
| 1 | 1 |
+---------+----------+
| 12 | 1 |
+---------+----------+
| 14354 | 1 |
+---------+----------+
To 'like' a theme, just insert the user and theme id into the table. The rest is just taking care of the response from the database - giving the user feedback for his try to like something more than once etc.
And of course you should not forget the ability to unlike - so you need to delete from the table again... if you want users to unlike.
First you have to create a new table with following fields (id, user_id, theme_id, status) as you said, maintain the relation between user and theme in that table.
when user like the theme insert a record with status 1 , if user unlike the theme, first check the user_id in the table, if user id is present then just update the status to 0 otherwise insert new entry with status 1.

How to add a few values in one line of mysql table?

I'm making an online game for a mounth i guess. I made user profiles, forget password, manage your account pages. And when they enter the game they can see their names and some information abut each other. Never mind of that.
Now, i need to do items for each users. So, here is my mysql table:
user_id | name | email | password | color | items | head | face | body | hand | feet | created
But i can add just one value into items col. How can i add all the item id's the user have? Please someone help!!!
You need a second table. Remove the "items" field from this table and create a new table called Items. In it you will have:
primaryKey | user_id | item
Then to get every item a given user has, you perform a SQL SELECT WHERE user_id=#id and iterate over the results.
There is a one to many relationship between the user and the number of items the user can have. You need to create another table with the following columns
user_id
item_id
item_desc
and store the item information there
You can store the ids as serialised arrays or create an user_item table.

How to protect the posting data / parameter is not modify by user and try to bypass the checking?

I am working on a shopping cart website,
I created a table to display to the user tp order like this:
+---------------------------------+
| My order list |
+----+------------+---------------+
| ID | NAME | ACTIONS |
| id | name | update delete |
| id | name | update delete |
+----+------------+---------------+
The problem is I identify the edit item like this:
mydomain.com/product_list/edit/1
Where 1 is the table ID of the product list
It is really dangerous as other user can delete the records of other by trying to tamper the id. How to secure this one? Even by posting, the hacker can just create a fake posting page, and post the fake id to the program.
Thanks
I've read your question and comments. And I think storing owners of tables in another table can help you (if I get you right)
You said
since the order id is just by number , e.g. order id 1 is the first record for customer A , order id 2 is for B, 3 for A etc... so if user B type in / post 3 as parmeter then he can delete the record of user A
Before you let me alter the table, you have to check if I've permissions for this. You can check my e-mail, my password, add them to session etc. But when it comes to check query string, you can simply look if this table is one of my tables.
So if user B type in / and post 3 as parameter, you can go and check if B is one the owners of table 3. If no, don't let B do anything.

PHP/MYSQL Newsletter read/unread system

i have a small problem.
Table (user_table)
id | username | name | password
Table (newsletter)
id | date
Table (newsletter_posts) <-- This table isn't very important for my problem.
The user_table is flexible, that means, sometimes i create new users, sometimes i delete users.
The newsletter table is also flexible.
This month
1 | 12345678
Next month
2 | 23456789
and so on...
But how can i create a read/unread table for all newsletter and all users. I have around 100 users and 12 newsletter per year.
Greetings
Dennis
You create a table that relates the newsletter table to the user table.
newsletter_user
----------------
id
user_id
newsletter_id
created_date
Existence of a row should occur (insert) when a user reads a newsletter. If there is no row, the user hasn't read the newsletter. Create a unique index on user_id,newsletter_id.
Just create a mapping table. You can name it newsletter_users_log. It can have columns like:
id -> BIGINT auto increment
newsletter_id -> foreign key to newsletter table
user_id -> foreign key to users table
date_sent -> DateTime
You should make a table that has
user id | newsletter id | status
Then you can query a newsletter to see who has read it or a user to see what newsletters they have read
If you want you can also add in some date fields, say for date read if you want to track that data.

Categories