Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hey guys, I want to create a databse that when someone comes to my home page they have a drop down box which contains all 50 states. Upon picking on state it brings you to that page where they can then pick from a list of wither sports (ie. baseball,hockey) level (minor league, major league). after that they wil be given all the options for there choice. They can then pick an option and it will bring them to a custom page with that team. So heres an exaple, I pick Massachusetts on the home page, then I pick major level and football on the MA page which brings me to a choice of the New England Patriots and maybe a couple semi pro teams. I then pick the NEPatriots and it goes to there page. On that page I want a contact page (i can write that). How would I organize this, would I use one database. Keep in mind that there are probably going to be a couple thousand teams all together so I am figuring to try and keep all this inside a database. Is this my best bet. Please point me in the right direction.

Of course you would use one database. Using multiple databases would be stupid. I think the real question is do you want multiple tables in that database.
When designing a database I usually start at the most specific data and work out to more general data.
I don't know if you planned to create the team pages from the database, but you absolutely should. It wouldn't make any sense to put all this work into a database driven site and then create a bunch of flat HTML pages (but you could simply dump the HTML into a single field for each team - it all depends on your design)
So, at the very specific level you will need a Teams table that will have fields such as: id, name, state, sport, level.
Now you have two options for (state, sport & level). You could either enter the value directly intot hat field OR you can store an ID to the relevant value in another table.
For example, you could enter "Baseball" into the sport field. Or, you could have another table for sports with an id and the name. Then in the Teams table you would enter the sport id intot he sport field.
The first approach would be the easiest and quickest solution. The second option will give you much more flexibility - especially for managing the site going forward.
Michael J

Hi Michael, on the part about building a page using the database, I have not had any experience doing this although I have seen pages done this way. Give me a quick lesson on this, I assume all the info is in the base and I create an HTML page that is a template and when called it is filled with all the fields of the database, something like that. I will research it a little more but could you give me a couple pointers.

Using PHP lets assume you have a table for the teams which has data is distinct fields that you want to display: name, wins, losses, sport, etc.
You would simply query the database for that team's data and then build the page:
<?php// Connect to DB
$dbh = mysql_connect('HOSTNAME','USERNAME','PASSWORD') or die (mysql_error());
mysql_select_db("DATABASENAME') or die (mysql_error());//Get the team ID passed on the query string
//i.e. URL = mydomain.com/showteam.php?id=5
$team_id = $_GET['id'];//Create the query
$query = "SELECT * FROM team_table WHERE id = '$team_id'";//Run the query
$result = mysql_query($query);//Extract the data from the results
$data = mysql_fetch_assoc($result);//Build the page
echo "<html>\n";
echo "<head>\n";
echo " <title>Details for {$data['name']}</title>\n";
echo "<head>\n";echo <body>\n";
echo "Team Name: {$data['name']}<br />";
echo "Sport: {$data['sport']}<br />";
echo "Wins: {$data['wins']}<br />";
echo "Losses: {$data['losses']}<br />";
echo "Percentage: " . ( $data['wins'] / ($data['wins']+$data['losses']) ) . "
";echo <body>\n";
echo </html>\n";?>
Michael J

Ok, this is becoming easier to understand. I have been reading on this stuff all day. A couple things.
The $data in your code represents what?
Should I have one table set up for each state and thats it or should I have several tables set up and use the state as the primary key.
Lastly, on the page set up, This is going to need html tables set up so basically should I just use the echo command to do the tables as well.
I appreciate the help

$data is an array of the data for the particular team I queried from the database
You should have one table
Just build your page any way you want in HTML and insert the variable data where it goes.
Michael J

I see, that makes it so much easier. I think I was just thinking too much on this subject becasue it is all coming into place now.
Alright so assume I have a DB set up with 1 table. If there is only one table then is there a primary key, I assume there should be but since I do not have email addresses for all the teams then what is my next best key.Can I put anything in each field, including pictures? I ask this because when I create the HTML document I am going to want to call the graphics from somewhere, whoudl I have an images folder or should (can) I put the graphics into the table, this might be a stupid question but I will ask anyways. Also, I am going to have a form on each page that will allow someone to send an email to the team, a real basic form that I use with everything but I want it to automatically fill in the info such as team name, I can justt use the same code you wrote previously to put that info in I assume.
I have been doing research on this but cannot seem to find exactly what I need to know, I think I need to understand databases more but everything is geared towards programming, not building. I appreciate the time Michael.

You don't absolutely need to specify a key, but it is definitely good practice. All you need to do is include an "ID" field in the table and specify that the field is unique and auto-incrementing. Then if you every have related tables you will tie the information together with that ID.
Regarding the pictures, you *can* put the actual image file content into the database, but I wouldn't suggest that. Either, I would save the file name and location to a field in the database or I would simply name each image according to the team ID.
Using a forum to learn about how to use a database for an interactive website is not very conducive. I suggest you find a tutorial and work through it.
Michael J

I see your point with not putting pictures into it, I will just create a seperate image file and tie the image in with the id name as suggested. Good Idea.
Now when someone goes to say the RedSox page, there are going to be pictures and a background on each page representing whoever the page is for. How do I make it so when someone visits a page that page is automatically filled with these pics without creating hundreds of flat HTML pages, unless that my only option?

Use some type of server-side scripting to build your pages dynamically. Just create the HTML "template" and use variables to populate the variable data.
Again, this is a subject that can't be properly explained in a furum. I'd suggest learning a little PHP.
Michael J

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |