Create a mysql table on the fly with supplied variable/s?

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
dano2000
Forum Newbie
Posts: 3
Joined: Mon Mar 01, 2010 4:54 pm
Location: Morristown, TN

Create a mysql table on the fly with supplied variable/s?

Post by dano2000 »

Noob here... Flames, jabs, I know I got it all coming....
I have a php/myspl db. Trying to store a meeting registration db...
I got a table for meeting and table for users.
When the user creates a new meeting they supply seats available($seats) and reserve seats available($resseats) lets say.
So where do I start when I want to create the table on the fly to store seats based off of the $seats and $resseats variables.
I know, I will have to loop to create the field names for the table on the fly.
Can I loop within a CREATE TABLE statement? Not sure what that would look like.
Or do I need to create and set of field names first, then shove them into the CREATE TABLE?
Sorta brain fried and brain blocked here.
Just kinda need a push in the right direction.
I understand the basics of php and mysql and have php putting and getting info from mysql db.
I admit though this is a little above my head.
Thanks for any info.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Create a mysql table on the fly with supplied variable/s?

Post by AbraCadaver »

Why do you want to create a table for a meeting. Why not store all meetings in the meetings table?
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
dano2000
Forum Newbie
Posts: 3
Joined: Mon Mar 01, 2010 4:54 pm
Location: Morristown, TN

Re: Create a mysql table on the fly with supplied variable/s?

Post by dano2000 »

I already have a table for the meeting. I want to create a table on the fly, when the meeting is entered by user, to have fields to hold the userid's of the participants that want to attend the meeting.

Sorry if I am not explaining well.

already have meeting tbl (meetingid, meetingname, maxparticipants, maxreserveparticipants, date, location ect...
already have user tbl ( userid, fname, lname, email)

what I want is to use the maxparticipants and maxreserveparticipant numbers to create a table that holds the userid's of the people who want to sign up. maxpart and maxres numbers may be different for each meeting based on user input.

participant table (meetingid, participant1/userid, participant2/userid until == maxparticipants)
I want this table/s to be created when the user creates the meeting.
Hope this makes sense.
Last edited by dano2000 on Mon Mar 01, 2010 5:47 pm, edited 1 time in total.
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: Create a mysql table on the fly with supplied variable/s?

Post by Eran »

What you need is a meetings_to_users table that hold the relationships between users and meetings. This table should hold the information for all meetings and not be created on the fly.

Code: Select all

meetings_to_users
 - meeting_id
 - user_id
 - status
 - created
 
dano2000
Forum Newbie
Posts: 3
Joined: Mon Mar 01, 2010 4:54 pm
Location: Morristown, TN

Re: Create a mysql table on the fly with supplied variable/s?

Post by dano2000 »

pytrin, I think I see where you are coming from and this makes better sense than the chaos I was trying to create. I appreciate the information.
Post Reply