SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2002
    Location
    KSA
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    2 drop down menu with php and mysql

    Hi

    I used mySql and have two tables, one for categories and the other for articles. One categorie may have many articles.
    I need 2 drop down menu (categorie and article) in which the data will be retrieved in the database.
    The items in the drop down menu of articles will be changed when I click in one categorie associated.


    Thanks

  2. #2
    SitePoint Evangelist
    Join Date
    Feb 2004
    Location
    Sofia, Bulgaria
    Posts
    421
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if you want to change the content of the second drop-down menu dynamically you'll have to use Java Script.

  3. #3
    SitePoint Enthusiast
    Join Date
    Jan 2002
    Location
    KSA
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I need to this code javascript

    How is use ?

  4. #4
    SitePoint Evangelist
    Join Date
    Feb 2004
    Location
    Sofia, Bulgaria
    Posts
    421
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    use php to fill in the java script arrays for the combo boxes.. for the java script code check this:
    http://www.javascriptkit.com/script/cutindex16.shtml

    if you can't understand something in the java script code, ask in the java script forum

  5. #5
    SitePoint Enthusiast
    Join Date
    Jan 2002
    Location
    KSA
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK

    Thanks

  6. #6
    SitePoint Wizard edshuck's Avatar
    Join Date
    Jul 2000
    Posts
    1,200
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I may be doing what you want in php and mysql with no java script.

    I have 2 cats. The first is a general cat and the second is much more specific. To see them work, go to www.noevalley.com and on the left column, find Shops and Svcs. Pick an item, say dining. then click GO.

    There are many places to eat in my neighbborhood (some I can afford

    They print in the middle and at the top of the new output, there is a drop down with specific categories and lots of eateries following. Pick a type, say French. Select dining-french and the list is cut to two selections only.

    This is done with five tables (cats, menu1, menu1 to cats, cats to shop and shop).

    Lets take a shop called Luna serving French open for lunch and dinner.

    shop_id is auto assigned. Lets say 47
    Cats are French (cat_id=110), Lunch (cat_id=54) and Dinner (cat_id=273)
    menu1_id=34
    The many to many in the middle of the shop and the cats will have

    47 110
    47 54
    47 273

    The many to many in the middle of the menu1 and the cats will have
    34 110
    34 54
    34 273

    cats_id and cat_name is the entire category table
    menu1_id and menu1_name is the entire menu1 table
    shop is hugh for me with maybe 12 to 15 fields. But thats ok.

    To add to the drop down, just add to the menu1 and make sure to pick some categories to work to.

    To add a category, also add to menu1 and to the applicable shops.

    If you need the select code, just mention and I will send. It really needs to be reworked into functions and oop.

  7. #7
    SitePoint Member
    Join Date
    Jul 2004
    Location
    Toronto
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Take a look on this:

    http://www.zend.com/zend/tut/drop-down.php

    I hope this it'll help you

    Thunderstruck

  8. #8
    SitePoint Member
    Join Date
    Aug 2004
    Location
    Australia
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Is my problem much the same?

    Hi Everyone,

    As a newbie I am wondering if my problem is much the same.
    I have two MySQL tables, for example:

    products (table)
    id category
    1 house
    2 animal

    sub_products (table)
    sub_id subcategory cat_id
    10 bird 2
    20 cat 2
    30 dog 2
    40 fence 1
    50 gate 1
    60 horse 2

    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 within the same screen, for example:

    User selects one from drop down list:
    Category:
    ..house ... animal

    The user can select from the matching subcategory:
    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.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •