Computing.Net > Forums > Web Development > database build

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

database build

Reply to Message Icon

Name: BigShow
Date: November 30, 2007 at 22:56:10 Pacific
OS: vosta
CPU/Ram: pentium
Product: dell
Comment:

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.



Sponsored Link
Ads by Google

Response Number 1
Name: Michael J (by mjdamato)
Date: December 1, 2007 at 12:56:12 Pacific
Reply:

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


0

Response Number 2
Name: BigShow
Date: December 1, 2007 at 13:34:58 Pacific
Reply:

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.



0

Response Number 3
Name: Michael J (by mjdamato)
Date: December 1, 2007 at 15:32:18 Pacific
Reply:

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


0

Response Number 4
Name: BigShow
Date: December 1, 2007 at 22:18:11 Pacific
Reply:

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


0

Response Number 5
Name: Michael J (by mjdamato)
Date: December 1, 2007 at 23:20:27 Pacific
Reply:

$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


0

Related Posts

See More



Response Number 6
Name: BigShow
Date: December 2, 2007 at 21:08:09 Pacific
Reply:

Hi Michael, you say one table. I have 50 states, shouldnt I have 50 tables one for each state?


0

Response Number 7
Name: Michael J (by mjdamato)
Date: December 2, 2007 at 22:50:28 Pacific
Reply:

No. You should have a column in the table to identify the state.

Michael J


0

Response Number 8
Name: BigShow
Date: December 3, 2007 at 06:56:02 Pacific
Reply:

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.


0

Response Number 9
Name: Michael J (by mjdamato)
Date: December 3, 2007 at 08:25:20 Pacific
Reply:

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


0

Response Number 10
Name: BigShow
Date: December 5, 2007 at 16:52:02 Pacific
Reply:

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?


0

Response Number 11
Name: Michael J (by mjdamato)
Date: December 6, 2007 at 13:49:00 Pacific
Reply:

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


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

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


Go to Web Development Forum Home


Sponsored links

Ads by Google


Results for: database build

Creating webpage with database www.computing.net/answers/webdevel/creating-webpage-with-database/2230.html

Template for database site www.computing.net/answers/webdevel/template-for-database-site/1516.html

Webpage linked to access database www.computing.net/answers/webdevel/webpage-linked-to-access-database/797.html