Jump to content

Syncronising PHP to MySQL


burkek4

Recommended Posts

Hi.

 

I have a table saved in MySQL

The name of the table is 'tournaments'.

One of the fields in this table is 'tournament_name'.

There are 10 tournaments within this table.

 

I also have a Expression Web 4 form where users enter a their names, addresses etc and select which tournament they want to play in from a dropdown dox.

 

Mu question is this. What PHP code do I use to let users choose from the 10 tournaments? The dropdown box from the form needs to be linked to the right table, then the right field; HOW do I do this??

 

Thanks

Kevin

Link to comment
Share on other sites

Hmm, what you are really asking is to explain how to work with a relational database. That's kind of a very broad topic that can't be adequately covered in a forum post. But, I'll see what I can do:

 

First off, your terminology about linking the user to the right table and the right field seems to indicate a lack of understanding. So, let's start with the tournaments table. In addition to the tournament_name field you should have a tournament_id field that is set as the primary key and has an auto-increment integer value. You would not need to ever add/edit this value - it would be controlled by the database. The primary key is how you will reference the value.

 

Now, you will need a second table to store the user's selections. Typically, you would have a "users" table and then use a third table to indicate which users have signed up for which tournaments. If users can sign up for multiple tournaments then you will definitely need to do this. However, if users can only sign up for one tournament you can just get away with a users table - although it is not a good practice.

 

So, let's take the simpler second approach. When you provide the user the form, create a select list using the id of the tournaments as the value and the name as the label/text. When the user submits the form along with their personal info and the selected tournament, you would store that information into the user's table. That table will have what is called a foreign key to link it back to the selected tournament. You could name the field "tournament_id" just like you do in the tournament table (this makes it easy to identify the relationships between tables). So, your user table will now have a record for each user alone with a key so you can determine which tournament they signed up for.

 

Now to properly use this data you will need to learn and understand how to do JOINs in your queries. Which I am not going to go into here. This is really just scratching the surface. I suggest taking some time and reading through a few tutorials.

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.