PHP Foreign Key UPDATE SELECT

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
amrelewa
Forum Newbie
Posts: 4
Joined: Mon Apr 04, 2011 4:12 pm

PHP Foreign Key UPDATE SELECT

Post by amrelewa »

I want to do something on my website, but I still dont know how to do it yet. I have two tables in my database, one is called users and the other is called groups.

fields in the first table
userid - firstname - lastname - email - birthday - gender - password - user_level - signup_date - last_login - activated - account_type - account_owner_name - account_routing_number - account_number - shares.

fields in the second table
groupid - groupname - numberofmembers - paymentamount - paymentrounds - email.

When a user CREATE a group, I insert the group's information in the first table in the same row where his/her information inserted. Also, I send the group's information plus his/her email address to the second table.

I want to know how to do the following:
1) Insert the group's information when someone ENROLL in the group.
2) Select First and Last name of members who are enrolled in the same group.

This is what I tried to do after I made some research.
I created a third table named it users_groups with two fields userid and groupid ... I tried to make a relationship between userid in users_groups and userid in users table and the same relation between groupid fields but it didnt work (When I input any data, the users_groups did not update). Note: I changed the engine to InnoDB and choose CASCADE in both delete and update.
fugix
Forum Contributor
Posts: 207
Joined: Fri Mar 18, 2011 8:01 pm

Re: PHP Foreign Key UPDATE SELECT

Post by fugix »

i would add another field to the second table with an array of the names of members in that specific group. then you can draw out the names using ("select names from second_table where groupid='$group_id'"), this is assuming that you name the new field 'names'.
amrelewa
Forum Newbie
Posts: 4
Joined: Mon Apr 04, 2011 4:12 pm

Re: PHP Foreign Key UPDATE SELECT

Post by amrelewa »

But, I will have multiple rows for the same groups with different names.
fugix
Forum Contributor
Posts: 207
Joined: Fri Mar 18, 2011 8:01 pm

Re: PHP Foreign Key UPDATE SELECT

Post by fugix »

im not sure what you're saying but i answered question number 2
fugix
Forum Contributor
Posts: 207
Joined: Fri Mar 18, 2011 8:01 pm

Re: PHP Foreign Key UPDATE SELECT

Post by fugix »

("select names from second_table where groupid='$group_id' and groupname='$group_name'")
fugix
Forum Contributor
Posts: 207
Joined: Fri Mar 18, 2011 8:01 pm

Re: PHP Foreign Key UPDATE SELECT

Post by fugix »

not sure if thats what you are saying
Post Reply