Jump to content

MYSQL Relationships, Indexes and Keys...will pay $ if you help me...seriously!!


ryan656

Recommended Posts

Hello All,

 

I am farily new to PHP/MYSQL and my company has just put me on a client requiring a social networking site. 

Ive gotten a long pretty good (user registration, login, profile page, etc..) but Im stuck now.

 

I need to integrate 3 sections (tables in the database) of the site: the Members, the Groups and the Events sections.

Basically the admins are going to create groups which members can join, then the admins are going to associate events with these groups and charge $ for tickets to the events.

 

So I need a way to keep track of all the users in a certain group and all the users who have RSVP'd for an event.

 

The natural thing that comes to mind is having an array as an field in the groups or events table with the id of any member thats in that group or attending the event.

I dont think that is possible with mysql, or any database actually so the next logical thing is using foreign keys inside the events/groups tables that relate to the member id's.

 

Is that something that can be accomplished.  I am basically open for any ideas that will help me get this done.

 

I WILL GLADLY PAY ANYONE WHO CAN HELP ME THROUGH THIS PROBLEM, I AM A FAST LEARNER SO YOU WONT BE WASTING YOUR TIME>

 

THANKS

 

Ryan

 

ryan@gomodi.com

Link to comment
Share on other sites

The three core tables:

 

member.id

member.name

 

event.id

event.name

 

group.id

group.name

 

A table to track events rsvp:

 

event_rsvp.id

event_rsvp.event_id

event_rsvp.date

 

A table to track members in groups:

 

member_in_group.member_id

member_in_group.group_id

 

To get a list of all members and their associated groups:

 

SELECT member.id
    , member.name
    , group_concat(group.name SEPARATOR '\n') AS groups
FROM member
    LEFT JOIN member_in_group ON member.id = member_in_group.member_id
    LEFT JOIN group ON member_in_group.group_id = group.id
GROUP BY member.id
ORDER BY member.name

 

To get a list of all members that have rsvp'd an event:

 

SELECT member.id
    , member.name
    , event.name
    , event_rsvp.date
FROM event
     INNER JOIN event_rsvp ON event.id = event_rsvp.event_id
     INNER JOIN member ON event_rsvp.member_id = member.id
WHERE event.id = $event_id;

Link to comment
Share on other sites

I was thinking a useful query would be "members who have NOT rsvp'd to an event", but that would require knowing which members were invited in the first place.

 

As invite is by group, I suggest another table of invited_groups, associating invited groups with events (or invited_members, associating invited members with events) if you prefer it at that level.

Link to comment
Share on other sites

To get a list of all members that have NOT rsvp'd an event:

 

SELECT member.id
     , member.name
     , event.name
     , event_rsvp.date
FROM member
     LEFT JOIN event_rsvp ON event_rsvp.member_id = member.id
     LEFT JOIN event ON event.id = event_rsvp.event_id AND event.id = $event_id
WHERE event_rsvp.member_id IS NULL;

 

something like that anyway.

Link to comment
Share on other sites

yeah... event_rsvp would certainly make a good double for an invitation record with date set to null as default making the NOT rsvp'd query a great deal simpler:

 

event_rsvp.id

event_rsvp.event_id

event_rsvp.member_id <= forgot this member earlier

event_rsvp.date

 

SELECT  member.id
     , member.name
     , event.name
FROM event_rsvp
     INNER JOIN event ON event_rsvp.event_id = event.id
     INNER JOIN member ON event_rsvp.member_id = member.id
WHERE event_rsvp.event_id = $event_id AND event_rsvp.date IS NULL

 

much better!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.