SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Jun 2005
    0 Post(s)
    0 Thread(s)

    populating form menus conditionally

    Hi everyone,

    I have a form which will allow me to populate a garments table within my database. Among the elements in the form, there is a suppliers drop down menu and a categories multiple select menu. I used the following code to populate these menus.

    PHP Code:
    // this code always runs, and gets lists of suppliers and garment categories
    $db=new Database('localhost','root','password','catalogue',0);
    $getSuppliers 'SELECT * FROM suppliers ORDER BY supplier';
    $suppliers $db->query($getSuppliers);
    $getCategories 'SELECT * FROM categories ORDER BY category';
    $categories $db->query($getCategories);
    There is also a colours menu, a sizes menu, and a garment type menu in the form. Instead of having these populate with the entire contents of their respective tables, I wanted to have each of them populate conditionally according to which supplier was chosen, ie. if a particular supplier was chosen, each of the menus mentioned would contain data specific to that supplier.

    I guess you'd need to know a bit about the database structure for this: The garment types have their own table with its primary key also in the garments table as a foreign key. Since the supplier_id also exists in the garments table as a foreign key, I guess the connection between these two could be made.

    The sizes and colours each have their own table and there's also garment_to_colour and garment_to_size lookup tables. These lookup tables contain the garment_id primary key from the garments table as well as the respective colour_id and size_id foreign keys from each of their tables.

    I just wondered if someone could show me what the code might look like, in one of these scenarios?

    Really appreciate any help offered.

  2. #2
    SitePoint Addict Robert_2006's Avatar
    Join Date
    Jun 2006
    Tarpon Springs Fl.
    0 Post(s)
    0 Thread(s)
    You will have to use javascript/ajax or have the form be submited to get the variables and populate them on the next page based on the submited data. I hope that gives you someplace to look.

  3. #3
    SitePoint Evangelist
    Join Date
    Aug 2005
    0 Post(s)
    0 Thread(s)
    Computers and Fire ...
    In the hands of the inexperienced or uneducated,
    the results can be disastrous.
    While the professional can tame, master even conquer.


Posting Permissions

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