Jump to content

Recommended Posts

What would be the best way to go about having categories in mysql. I would like to have 1 table, and each item will have an id number. I want the items to go into a main catagory, and one subcatagory. How could this be achieved easily?

 

Example Item: Ice Breath

Main catagory: Attacks

SubCatagory: Elemental

 

(I just came up with this, and has nothing to do with my project, so don't say anything specific to this please :))

Link to comment
https://forums.phpfreaks.com/topic/62986-mysql-table-organization/
Share on other sites

Everything on a website can be displayed in one database. Each table holds diffrent data such a on table could hold users. this users table could hold id, username, password, ip, date signed up, ect... another could hold a forum such as display topics, display name, display id ect... This is the most default way of running mySQL and in my opinion the best way! Hope that helps?

With just one table?

 

uniqueID | catID | subcatID | itemID | title | description | etc...

 

Then some examples:

1 | 1 | 0 | 0 | Attacks | attack thy enemy! | ... (category)

2 | 1 | 1 | 0 | Elemental | an element feature | ... (sub-cat)

3 | 1 | 1 | 1 | Ice Breath | Icy cold | ... (item)

4 | 2 | 0 | 0 | Defense | stand true soldier | ... (category)

5 | 2 | 1 | 0 | Physical | get involved | .. (sub-cat)

6 | 2 | 1 | 1 | Blockage | dont get hit | ... (item)

7 | 2 | 1 | 2 | Duck | miss that swing | ... (item)

8 | 2 | 2 | 0 | Verbal | yell at him | ... (sub-cat)

9 | 2 | 2 | 1 | Intimidate | make him fear | ... (item)

 

 

There's probably a better way, but that's just a suggestion.

 

edit: I guess it would be better to explain it a little too:

You could easily run it to where if(subID == 0), then it's a category, if((subID != 0) && (itemID == 0)) then its a sub category, if(itemID != 0) its an item. Then finding the sub categories for each category would run a query like ("SELECT * FROM `tablename` WHERE `catID`='".$catID."' and `subID`!='0'") etc.

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.