Question

i have a small problem.

  1. Table (user_table)

    id | username | name | password

  2. Table (newsletter)

    id | date

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

Was it helpful?

Solution

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.

OTHER TIPS

Just create a mapping table. You can name it newsletter_users_log. It can have columns like:

  1. id -> BIGINT auto increment
  2. newsletter_id -> foreign key to newsletter table
  3. user_id -> foreign key to users table
  4. 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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top