Discuss game comparison database design help in the MySQL Help forum on Dev Shed. game comparison database design help MySQL Help forum discussing administration, SQL syntax, and other MySQL-related topics. MySQL is an open-source relational database management system (RDBMS).
Receive the tools necessary to be the rock star of your field. Our 12-month program teaches you the evolving world of multi-channel marketing as well as the complex issues and opportunities found in the industry.
ASP Free and Iron Speed Designer are giving away $5,500+ in FREE licenses. Iron Speed's RAD CASE toolset can save up to 80% of your coding time. One free license per week, one perpetual license per month! Download and Activate to enter!
Web development can be a daunting task, even for specialists. There is a lot of information to absorb and a lot of technologies to learn in order to manage a superior website. When trying to learn the ropes, developers need a reliable source to introduce new ideas that can be easily implemented. When working on large projects, even web veterans may run into a technology or an aspect of a technology that they are unfamiliar with.
What would be the best way to design the database relationally?
Currently, I have a main "compare" table that has: "id", "gameID", "circa", "genreID", "publisherID", "engineID", and "developer" fields.
The "games" table has "gameID" and "game" fields.
No "circa" table since it's just a 4-character year that gets entered (although I suppose I could have a table with all the different years but surely there's an easier way to sort by year without having to have the year in a separate table?).
"genres" table has "genreID" and "genre" fields (do I have to have genres in a separate table like this in order to be able to efficiently sort them?). I want multiple genres to be selected from checkboxes, including a text-entry field for unlisted genres.
"publishers" table with "publisherID" and "publisher" fields (same issue as above)
"engine" table with "engineID" and "engine" fields (same issue as above)
No "developer" table for same reason as no "circa" table.
I'm finding that having all these tables makes it a bitch to do SELECT statements and stuff--but perhaps I'm not doing them right. Argh...please help!
Posts: 14,802
Time spent in forums: 1 Month 1 Week 4 Days 4 h 32 m 44 sec
Reputation Power: 1059
Read through some of the already posted forums related to relational databases, what they are, how they work, etc. Search the internet too. The queries are probably the hardest part, but the forums have many posts with examples of queries in a relational database. For this reason, I'm not going to get too far into this, just a few notes and pointers.
Ordering results in a query is done using ORDER BY column, so this notion that having things in a different table so that you can sort/order more efficiently seems a little skewed.
Code:
SELECT column1, column2
FROM table1
WHERE column1='condition'
ORDER BY column2
The use of separate tables for separate information is for storage efficiency. Though not always the case, try to think of table relations as a one-to-many relationship. There are `many` games within `one` genre. `table.genres` has a one-to-many relation to `table.games`. The genres tables holds the name of each genre once and the games table holds the id of that genre. To change the genre's label (let's say you misspelled it), you change it once in table.genres and it's reflected in all references from table.games.
__________________
# Jeremy
Explain your problem instead of asking how to do what you decided was the solution.
Posts: 39
Time spent in forums: 21 m 48 sec
Reputation Power: 10
I've read through plenty of relational database websites and forum posts but I'm still unsure.
Shouldn't just the game names be in the "games" table since there can be at least 2 games with the same name if the name is common enough?
I have the game's genre(s) in the main "compare" table which is the compilation table of all the other tables--the 4th order of normalization or whatever it's called.
The reason I have a separate table for genres is because I've seen some tutorials suggest using a table for checkbox values instead of using a "set" datatype. If you know of a better way, please let me know.
I also want the checkboxes to be checked when editing the game's genre (among other things--the form is mostly made up of checkboxes but I want to be able to support same-named text-entry fields for most of the checkboxes).
Posts: 14,802
Time spent in forums: 1 Month 1 Week 4 Days 4 h 32 m 44 sec
Reputation Power: 1059
First thing: that is one huge form! Maybe a multipage form with one section per page would be better? Just a suggestion.
The form helps me see what kind of informatin you're trying to store and gives me a better idea of how you're trying to use it. That's a lot of information for sure. Is this your first experience in databasing? Seems like a large first project if it is.
Quote:
... I want to be able to support same-named text-entry fields for most of the checkboxes ...
Just to be clear, does this mean that you want a user to be able to enter text for `something` for which there is no checkbox? If so, do you want to store that newly created `something` in a table so that when the form is created next time, it appears as a checkbox? Thus, effectively allowing users to create checkboxes for your form so that no `something` is left out, and so that future users have that same option?
I think I'd have to see a full printout of your table structures to really be able to help.
The form will eventually be split up into separate pages, which is why I've started separating the form categories into separate tables--and some of those categories, particularly engine and level/world design, will most likely be split up into separate tables/pages too, similar to how MobyGames has its game submission set up.
It IS a big first project for a database but I've been wanting it for years and since no one's ever contacted me about helping me create it, I figured I'd just break down and attempt it myself. Unfortunately, I don't enjoy programming but I'm willing to learn at least PHP if it will help me do what I want with all this info.
As for the text-entry fields, most (if not all) will have checkboxes associated with them, as is layed out on the game entry form; the text-entry fields are there to accept more detailed info pertaining to the checked feature. So if someone checks the genres "action" and "adventure", and they believe the game to include something else not listed (like "educational" or a more detailed genre description), they'll be able to enter that info in the text-entry field and it will go in the appropriate "other genre" field in, I guess, either the "genres" table or perhaps the main "compare" (ID compilation) table? I'm not sure.
However, what you mentioned about allowing people to add options (after I validate them, of course) would be convienent, since MobyGames also allows this with developers/publishers anyway--it would be great to take it a step further and have it apply to other attributes too!
CREATE TABLE users (
id tinyint(4) NOT NULL auto_increment,
name varchar(20) default NULL,
email varchar(50) default NULL,
password varchar(20) NOT NULL default '',
PRIMARY KEY (id)
) TYPE=MyISAM;
They're obviously unfinished as to all the fields they'll contain but they're basically going to be split up like the game form categories--and subcategories where everything is bolded on the left side: engine (type, atmosheric/environmental effects, collision detection, lighting, particle effects, etc)--though I'm not sure what I can leave out of separate tables and what I can just use sets/enums/arrays/whatever for.
Anyway, any advice you can give would be great--thanks again.
Last edited by Eepē : September 26th, 2002 at 02:49 AM.
Posts: 14,802
Time spent in forums: 1 Month 1 Week 4 Days 4 h 32 m 44 sec
Reputation Power: 1059
Just a note: In the `compare` table you have genreID field with a set. Do you plan on having only 6 genres? What happens if you did what was discussed and allow people to generate genres on the fly in the form? Additionally, the way you describe it, a single game could belong to many genres. So how did you plan on storing mulitple genres in the table?
Also, the genreID is a tinyint(1), which limits you to 1-9. I notice this is done a lot throughout your tables and I understand your intentions, but if you're auto-incrementing you may want to make those a little larger.
Not knowing PHP very well is hendering your creation of the database as well since you don't know how you'll have to, or be able to, work with the data in database easiest with regards to PHP.
Expect to have a fair number of tables in this database. Some of them you might think are pointless, a waste, or would grow too large, but that's what they're for. Let me see if I can give you an example using what you have so far:
table.game
gameID
game
table.genres
genreID
genre
If a game only belonged to one genre then you'd simple add genreID to table.game and it would store the ID from table.genres for the related genre. However, with your plans, you'll need another table:
table.assign_genres
ID
gameID
genreID
Now if you had a game with ID of 1 and it belonged to the genres with IDs of 4 and 5, your table contents would look like this:
ID | gameID | genreID
1 | 1 | 4
2 | 1 | 5
table.assign_genres has the potential to have a lot of records, but keep in mind all we're storing is numbers.
Posts: 39
Time spent in forums: 21 m 48 sec
Reputation Power: 10
I was just experimenting with the "genreID" set in the "compare" table, but isn't there a way to just add more genres to the set vs. having to create another table to handle the genre-game relationships that can seemingly be handled in the main "compare" table via the "genreID" field?
For example, if a game is "action" and "adventure", I have the "genreID" field as "1,2". The problem I'm having is how to get both numbers out individually and have their appropriate checkboxes appear checked when editing the game's entry. Right now it just adds the numbers together, totalling "3" and checks the "role-playing" box. Doh!
As for the tinyint(1), I'll increase it if more than 9 genres are added. If any fields are added I will approve them first and change their field type accordingly. Right now I have exactly 9 genres: action, adventure, role-playing, simulation (city/empire-building, driving/racing/riding), and strategy (real-time, turn-based). I may split up the simulation sub-genres which would, of course, require tinyint(2) but I just want to get the existing genres working correctly with their checkboxes first.
Posts: 14,802
Time spent in forums: 1 Month 1 Week 4 Days 4 h 32 m 44 sec
Reputation Power: 1059
You would pull that set as the string '1,2' and PHP explode() it into an array so that you had '1' and '2' separately. I've done databases both ways, storing an array as a string, like the way you've done it, and by using additional tables. It really just depends on preference and how you want it done -- though I believe that Bytes are save one way over the other. As I mentioned, not knowing the PHP is hendering you a little I think too.
Posts: 39
Time spent in forums: 21 m 48 sec
Reputation Power: 10
Well, I'm trying to learn both PHP AND MySQL simultaneously so that, of course, makes it more difficult.
I'll try the explode() on the set; I remember trying implode() for checkboxes from this DevShed tutorial but I forgot about it and didn't think to try it in the reverse.
How do I get the array values separately to appear in $genre and their checkboxes checked?
I have this so far:
$sql = "SELECT
*
FROM
compare,games,genres,publisher,engine
WHERE id=$id
AND compare.gameID=games.gameID
AND compare.genreID=genres.genreID
AND compare.publisherID=publisher.publisherID
AND compare.engineID=engine.engineID";
Then you'll need to read through the list of array functions and see if there's one you can apply. Possibly the in_array() function. Or run through the Control Structures documentations looking closely at while() and foreach().
I can't be too specific here b/c of the scope of the project.
Posts: 39
Time spent in forums: 21 m 48 sec
Reputation Power: 10
Ugh, I don't understand how to do this. The PHP manual shows foreach ($array as $v/$key/$whatever) but I don't know what the hell should go in $v/$key/$whatever and it's not explained anywhere on the "foreach()" page that I can see.
And what am I supposed to do with this anyway? Will it cause $genreID to have a separate number for the checkbox checking to work? If not, how do I get it to do that? :/
Posts: 14,802
Time spent in forums: 1 Month 1 Week 4 Days 4 h 32 m 44 sec
Reputation Power: 1059
PHP Code:
// This is a comma separated string
$string = '1,2,3,4';
// We make that string an array (or a list) with explode
$array = explode(',', $string);
// $array's values as an array
// $array = array('1', '2', '3', '4') ... or ...
// $array's values as associative array, i.e. $key => $value pairs
// $array = array(0 => '1', 1 => '2', 2 => '3', 3 => '4')
// Now we can move through each element in the list of numbers
// foreach(in array as [key =>] value) where [key =>] is optional
foreach($array as $value) {
// $value can be whatever you want variable wise
// it is used within the foreach statement, and temporarily
// holds the value of each element
echo $value . '<br>';
}
Posts: 39
Time spent in forums: 21 m 48 sec
Reputation Power: 10
I just want to have $genreID have a single number.
Will this work?:
foreach ($genreID as $genreID) { $genreID=$genreID; }
Seems kind of redundant...I don't want anything echoed or whatever--just put a single genre ID value into $genreID so the checkbox can be appropriate checked. Surely there's an easier way...
Testing the $genreID variable after the explode() function reveals it's not being exploded correctly in the first place; it's still coming up as "3". :/
Last edited by Eepē : September 26th, 2002 at 09:05 PM.
Posts: 39
Time spent in forums: 21 m 48 sec
Reputation Power: 10
Still doesn't work. :/
How can I list the contents of the array? If I just call $genres it says "Array".
OK, I used "print_r(array_values($genres));" and it gave "Array ( [0] => 3 )" so the explode() isn't doing its job or something...
Is the SELECT query (or perhaps "mysql_query($sql);" or "mysql_fetch_array($result);") pulling a string ("1,2") out of the genreID field or adding them together and making it "3"?
Last edited by Eepē : September 26th, 2002 at 09:34 PM.