Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > PHP Databases
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 3rd, 2004, 03:59 AM
Registered User
 
Join Date: Aug 2004
Location: , , Australia.
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.
Reply With Quote
  #2 (permalink)  
Old August 25th, 2004, 12:20 AM
Authorized User
 
Join Date: Aug 2004
Location: Seunderabad, Andhra Pradesh, India.
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
Reply With Quote
  #3 (permalink)  
Old August 29th, 2004, 04:14 AM
Registered User
 
Join Date: Aug 2004
Location: , , Australia.
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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 01:05 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.