• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 310
  • Last Modified:

Multiple choice related fields form

Dear all,

Let's say you have an on-line computer store, and you are creating an administration page so your employees can add new products to the database.

This administration page is a form with several fields. There's a name of product field, a price field, a list of areas where the new product belongs:

Hardware
Software
Games

And a list of sub areas:

Arcade games
Sport games
Tennis Games
Basketball Games
Editors
Animation software
Antivirus
Hard Drives
Precessors
Motherboards


Say that you are adding a new product using this administration and it is a game.

After filling in the name of the game and the price, you have to choose Software and Games in the areas list. Then only the sub areas related to  the  Software and Games areas  should show:

Arcade games
Sport games
Tennis Games
Basketball Games
Editors
Animation software
Antivirus

for you to choose the right sub area or sub areas .
How can I do that?

I'm thinking in a multiple select for the areas, but then how can I show just the sub areas related to the areas chosen? and then these sub areas have to be able to be selected amd submitted  with the rest of the form.

Also, how's the structure of the MySql table or tables? I still don't get how an area "understands" what is the sub area that belongs to it.

The technology  I'm  thinking of is: PHP, Javascript and MySQL

I'm lost, please help!!
Thanks in advance!
0
Dada44
Asked:
Dada44
  • 4
  • 2
1 Solution
 
amxCommented:
You should try working backwards.

Design the database tabels first, this will help you understand how the tackle the problem when you try to build the web page.

This tutorial will help you get started, it will help explain how an area knows about a sub area.

http://www.geekgirls.com/databases_from_scratch_3.htm
0
 
NerdsOfTechTechnology ScientistCommented:
TABLE CATEGORIES
=================
catID | Name
1 | Hardware
2 | Software
3 | Games

TABLE SUBCATEGORIES
====================
subID | catID | Name
1 | 3 | Arcade games
2 | 3 | Sport games
3 | 3 | Tennis Games
4 | 3 | Basketball Games
5 | 2 | Editors
6 | 2 | Animation software
7 | 2 | Antivirus
8 | 1 | Hard Drives
9 | 1 | Precessors
10 | 1 | Motherboards

PRODUCT TABLE
==============
prodID | subID | Name
1 | 3 | Street Fighter II
2 | 8 | Western Digital SATA 160GB 7200RPM 8MB Cache

See how the subCategory table references the catID (this is called a foreign key)...
Same with the product how it references the subID

In essence the connection is simplified into a 'tree' like structure
Category
 SubCategory based on catID
  Product based on subID
0
 
NerdsOfTechTechnology ScientistCommented:
CORRECTION: Street Fighter II isn't a tennis game :)

TABLE CATEGORIES
=================
catID | Name
1 | Hardware
2 | Software
3 | Games

TABLE SUBCATEGORIES
====================
subID | catID | Name
1 | 3 | Arcade games
2 | 3 | Sport games
3 | 3 | Tennis Games
4 | 3 | Basketball Games
5 | 2 | Editors
6 | 2 | Animation software
7 | 2 | Antivirus
8 | 1 | Hard Drives
9 | 1 | Precessors
10 | 1 | Motherboards

PRODUCT TABLE
==============
prodID | subID | Name
1 | 1 | Street Fighter II
2 | 8 | Western Digital SATA 160GB 7200RPM 8MB Cache

See how the subCategory table references the catID (this is called a foreign key)...
Same with the product how it references the subID

In essence the connection is simplified into a 'tree' like structure
Category
 SubCategory based on catID
  Product based on subID
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
Dada44Author Commented:
NerdsOfTech I think you got it!
The thing I still cannot figure out is the query to  show just the sub areas (or sub categories) related to the areas (or categories) chosen.

Thanks a ton in advance!
0
 
NerdsOfTechTechnology ScientistCommented:
SELECT subcategories WHERE catID = Selected Category
0
 
NerdsOfTechTechnology ScientistCommented:
So if the user chooses 2 for category
SELECT subcategories WHERE catID = 2

Output:
5 | 2 | Editors
6 | 2 | Animation software
7 | 2 | Antivirus
0
 
Dada44Author Commented:
Thanks!!!!!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now