Page 1 of 1

Database lists and categories with PHP

Posted: Sat Feb 07, 2009 9:14 am
by tomsace
Hi,

I have started my own arcade website. I wish to know how I could use MySQL to store data like game title, game url etc... and use it in my website, also I need to categorize this, like putting games in arcade, sports, shooting etc... so I can use a form to insert the details and it auto ads the game to the new games list and stuff like this. Or alternatively if there is any software out there I can download and install which is already set up with this sort of feature.

Thanks alot,

Tom.

Re: Database lists and categories with PHP

Posted: Sat Feb 07, 2009 2:19 pm
by JAB Creations
Relational databases rock, have you started messing with MySQL? It's not too difficult and it's absolutely necessary if you want to make your own database driven applications.

Relational databases are exceptionally valuable because they make your data dynamic (as CSS makes your site's styling dynamic).

You'll want to setup two tables in MySQL...

game
game_categories

You'll store the game information in the game table. However you won't store the game category there as that would be static...every game would manually have to store "RPG" or "Shooter". What you want to do is create an 'id' and 'category' column in the game_categories table. Then in the game category for a game you put the category's ID from the game_categories where you would have put "RPG" or "Shooter". When you need to pull information to display a game page you would use a JOIN in your MySQL. So you would SELECT from the game table however by using a JOIN the category ID for the category that is stored in the game table is replaced by the category_name in the game_categories table.

In another example think of how this would be useful for user names. You may want to charge people $2 to allow them to change their user name on your website. If that user had thousands of posts on your forums would you really want to manually have MySQL go in to each and every instance and replace their old user name with their new one? Heck no! You would only have to replace it once! Why? You would never store their static name for a post, you'd use their ID. Then when you display a forum post you would join the forum_posts table to the user_accounts table and their ID would be dynamically replaced with their user name!

If you can understand that then you'll understand why it's important to design how you'll construct your database first before you start coding the rest of your site. So think about what your requirements for your site will be and create the database based on that first. Do that and you'll be on your way. :)

Re: Database lists and categories with PHP

Posted: Sat Feb 07, 2009 3:50 pm
by tomsace
Wow, thanks alot. I definately have an idea on how it works now.
Thanks alot!