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
           }
	
	}

Recommended Answers

All 4 Replies

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.

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

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.

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
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.