Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You should have one table with one row for each user that exists, like you already do. Call it 'users'. This table will have only the information about the user, not which groups they are in.</p> <p>You should have another table with one row for each group, which you do. Call it 'groups'. This table will have only the information about the group, not who is in it.</p> <p>You should have a third table with one row for each user for each group they're in. Call it 'user_groups' or something. Each row in this table will link one user from the 'users' table to one group from the 'groups' table, and possibly give information about their subscription to that group.</p> <p>A sample setup may look like:</p> <pre><code>CREATE TABLE users ( userID INT, firstName VARCHAR, lastName VARCHAR, PRIMARY KEY (userID) ); CREATE TABLE groups ( groupID INT, groupName VARCHAR, adminUserID INT, /* this is the userID of the one and only administrator of this group */ PRIMARY KEY (groupID) ); CREATE TABLE user_groups ( userID INT, groupID INT, invited TINYINT, /* 0 or 1 to indicate true or false */ subscribed TINYINT /* 0 or 1 to indicate true or false */ ); </code></pre> <p><hr /> <strong>EDIT</strong> Answering question from comments:</p> <pre><code>$groupID = 1; $userIDArray = explode(",", $row["invitedusers"]); // assuming that $row is a row from the old group_data table foreach ($userIDArray as $userID) mysql_query("INSERT INTO user_groups (userID, groupID, invited) VALUES ('". mysql_real_escape_string($userID) ."', '". mysql_real_escape_string($groupID) ."', 1)"); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload