0

Hey Guys,

I need some assistance if possible. I am using MySQL & PHP, I have an "events" table with a row field called "Users_Attending" and can't seem to figure out the best way to add multiple users to an event rows "Users_Attending" field. I want to store user emails in the Users_Attending field like: user@test.com, user2@test.com, user3@test.com

I thought about using an array of some sort to store the user emails but not sure what I should do, any assistance would be greatly appreciated! Oh and the the function within my class that I am talking about is "add_to_list()" which is below, right now it works but it just replaces the old value stored in Users_Attending with the new value. Oh yeah and all I am storing in the $user = $_SESSION; is the current user's email address.

public function add_to_list(){

        $condb = new DBCON();
        $condb->startcon(); 

         $date = date("Y-m-d");
         $user = $_SESSION['User']; 


         $event = mysql_query("SELECT id FROM events WHERE Event_Date = '$date'");

         $event_row = mysql_fetch_row($event);
        
$list_query = mysql_query("UPDATE events SET Users_Attending = '$user' WHERE id = '$event_row[0]'");  
       
          if($list_query){

          //success

          }
           else{

           //failed
           }
	
	}
3
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by drewpark88
1

storing multi values in single field cell is not normalised way of storing data.
YOu must keep table with columns (eventid,user).

Another doubt
you are fetching event id using date. Now if there are two events on same date, then Which event is to be considered.

1

Below is normalization. Field names are self explainable.
Also as urtvi suggested check event uniqueness.

====================
Table Name : event 
====================
eventId  eventTitle date
1        Seminar
2        Robotics
3        AI

====================
Table Name : user
====================
userId  fullName  email
1       John      user1@test.com
2       Tanya     user2@test.com
3       Mathew    user3@test.com

===============================
Table Name : event_participant
===============================
participantId eventId userId
1             1       2
2             1       3
3             2       3
4             2       2
5             2       1
0

Thanks urtrivedi, appreciate the help! Also, under my circumstances I only need one event per day. :)

storing multi values in single field cell is not normalised way of storing data.
YOu must keep table with columns (eventid,user).

Another doubt
you are fetching event id using date. Now if there are two events on same date, then Which event is to be considered.

0

Thanks vibhadevit, these table examples really helped! Thanks a bunch! :)

Below is normalization. Field names are self explainable.
Also as urtvi suggested check event uniqueness.

====================
Table Name : event 
====================
eventId  eventTitle date
1        Seminar
2        Robotics
3        AI

====================
Table Name : user
====================
userId  fullName  email
1       John      user1@test.com
2       Tanya     user2@test.com
3       Mathew    user3@test.com

===============================
Table Name : event_participant
===============================
participantId eventId userId
1             1       2
2             1       3
3             2       3
4             2       2
5             2       1
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.