Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP Databases
|
PHP Databases Using PHP in conjunction with databases. PHP questions not specific to databases should be directed to one of the other PHP forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 3rd, 2004, 03:59 AM
Registered User
 
Join Date: Aug 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Category SubCategories and two MySQL tables

Hi Everyone,

I have two MySQL tables, for example:

products sub_products

id category sub_id subcategory cat_id
1 house 10 bird 2
2 animal 20 cat 2
                            30 dog 2
                            40 fence 1
                            50 gate 1
                            60 horse 2
and so on.

I would think to get the info from the two tables I would use a statement such as:
"SELECT id, category, sub_id, subcategory, cat_id FROM products,sub_products";

Once I have the data, I only want the user to select one category from a drop list field and display the matching sub-category drop list in another field, for example:

Category ......... house ........ animal

SubCategory ... gate ... dog
                        ... fence ... cat
                        ... roof ... bird
                        ... steps ... horse

Is it possible to do this with PHP using two MySQL tables within plain HTML?

I have seen a number of solutions requiring the category and sub-categories to be entered as options within the PHP code, but this is impractical as I could use up to 100 categorys and 1000 subcategories.

Thanks for any assistance.
 
Old August 25th, 2004, 12:20 AM
Authorized User
 
Join Date: Aug 2004
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to sinapra Send a message via MSN to sinapra Send a message via Yahoo to sinapra
Default

hi there
Let me tell you what i understood first. You have two categories 1 and 2. Now user should get a drop down showing both the categories.
Once he selects the category, he will get another drop down showing sub-category. Yes, it can be done if that is your question.
Display the cat-id in the first drop down [use distinct(cat-id)] and select the option user selects, trap the value in Javascript or PHP code and pass the value in the another query [MySQL doesnot support subquery]. Retrieve the values for sub-cat in another drop-down.
Let me know if I am clear.
Regards

sinapra
 
Old August 29th, 2004, 04:14 AM
Registered User
 
Join Date: Aug 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you sinapra,

You filled in the missing bit that I have been after. Works ok now.

Thanks again .... cjp_qld.

Quote:
quote:Originally posted by sinapra
 hi there
Let me tell you what i understood first. You have two categories 1 and 2. Now user should get a drop down showing both the categories.
Once he selects the category, he will get another drop down showing sub-category. Yes, it can be done if that is your question.
Display the cat-id in the first drop down [use distinct(cat-id)] and select the option user selects, trap the value in Javascript or PHP code and pass the value in the another query [MySQL doesnot support subquery]. Retrieve the values for sub-cat in another drop-down.
Let me know if I am clear.
Regards

sinapra





Similar Threads
Thread Thread Starter Forum Replies Last Post
Mysql Sorting results from multiple tables dcb22 SQL Language 8 October 25th, 2004 10:57 AM
Dynamically Link MySQL Tables at Runtime Rational Access 0 June 27th, 2004 09:15 PM
Display all tables in a mySql database question mb92010 MySQL 1 April 9th, 2004 04:26 PM
MySql tables godhsf80 PHP Databases 1 November 26th, 2003 01:27 PM
Locking tables using mySQL fcamilo Beginning PHP 1 June 13th, 2003 12:30 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.