Reputation: 1398
I need to show a modal window the first time the user logs in, after logging in, that modal window should not be displayed.
Questions:
I'm thinking of creating a field in the user table to be called, modal_first_time, and adding the values 0 or 1
0 = Modal not shown 1 = Modal shown
So that when you log in for the first time, perform a logging in that table and change the value from 0 to 1, so you do not show that modal window again.
But is this optimal? What if I have 10 modal windows, do I have to create 10 additional fields?
It is well the way to add a field in the table, or there is some more optimal and simple, the best would be a session variable but these when clearing Cookies or switching computers would show again.
Upvotes: 0
Views: 34
Reputation: 1203
I would suggest making a "Modal accessed" table.
This table would hold 4 columns.
UID, UserID, ModalID, accessed
To find if the current status of a Modal for a user you would run a SELECT in your "onLogin" event.
Below is a very rough example of how this could be utilized to work for 1 or many Modals
SELECT ModalID FROM `SchemaName`.`ModalAccessedTable`
WHERE UserID = "Bob"
AND Accessed = 0
OR another usage
SELECT Accessed FROM `SchemaName`.`ModalAccessedTable`
WHERE UserID = "Bob"
AND ModalID = 'ModalName'
Update access usage
UPDATE `SchemaName`.`ModalAccessedTable`
SET Accessed = 1
WHERE UserID = "Bob"
AND ModalID = 'ModalName'
With a setup like this you can select, and update each individual entry per userID as needed, with relatively efficient lookup efficiency.
Side Note: Assuming this table will become large, you will benefit greatly from properly build multi-column indexes.
Upvotes: 1