SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Addict trigger's Avatar
    Join Date
    Jun 2003
    Location
    Eagan
    Posts
    342
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Dynamically Updating List/Menus in Forms

    I got a toughie here I think. I want to create a form, that uses dynamic list boxes. They would pull the values out of a sql database table I have. There are three fields I want them to select from, one is called "vendor", one is called "product", and one called "version". I want them to be able to select "vendor", and then have the next menu populate "product" values from a query where vendor is equal to the vendor that has been selected. After "product" has been selected, I want the versions to populate from a query where "vendor" equals what is entered for vendor, and where product is equal to what is entered for product. What's the best way to go about this?

    trigger

  2. #2
    SitePoint Addict seanmayhew's Avatar
    Join Date
    Aug 2002
    Posts
    209
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've only seen this accomplished using JavaScript and Frames

  3. #3
    SitePoint Addict trigger's Avatar
    Join Date
    Jun 2003
    Location
    Eagan
    Posts
    342
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    JavaScript no good, how bout something like nested forms or something? I still believe that php is the answer, somebody show me the way!

  4. #4
    SitePoint Author silver trophybronze trophy
    wwb_99's Avatar
    Join Date
    May 2003
    Location
    Washington, DC
    Posts
    10,633
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    There is no way to do it without using a little javascript--you need to force the page to refersh without the user hitting submit.

    But, what you could do is setup the form to submit when a user changes the list box. Have it start selecting the vendors out of the database and have the other 2 list boxes based on queries based on vendor (so they would end up having no data to begin with). Then the user selects vendor, form updates to show products. Repeat for version.

    But you really cannot get around the javascript to fire the events.

    WWB

  5. #5
    SitePoint Member
    Join Date
    Jul 2003
    Location
    Reno NV
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by wwb_99
    There is no way to do it without using a little javascript--you need to force the page to refersh without the user hitting submit.

    But, what you could do is setup the form to submit when a user changes the list box. Have it start selecting the vendors out of the database and have the other 2 list boxes based on queries based on vendor (so they would end up having no data to begin with). Then the user selects vendor, form updates to show products. Repeat for version.

    But you really cannot get around the javascript to fire the events.

    WWB

    I am doing almost the same EXACT thing and have the same problems, How do I get the variable of what they selected and pass this to another query of another datbase? You mention javascript but gave no examples, (yea I am new to PHP and Java)Could i beg you to give some real life examples? here is the first table/form I am getting data from:

    <select name="Race" size="1">
    <?php
    do {
    ?>
    <option value="<?php echo $row_Race['race']?>"><?php echo $row_Race['race']?></option>
    <?php
    } while ($row_Race = mysql_fetch_assoc($Race));
    $rows = mysql_num_rows($Race);
    if($rows > 0) {
    mysql_data_seek($Race, 0);
    $row_Race = mysql_fetch_assoc($Race);
    }

    ?>

  6. #6
    La la la la la bronze trophy lieut_data's Avatar
    Join Date
    Jun 2003
    Location
    Waterloo, ON
    Posts
    1,517
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Firstly, Javascript != Java

    Secondly, you might have better luck with Javascript samples in the Javascript forum.

    Thirdly, in direct answer to Cmos's question, you don't even need Javascript. You will need to assign each option a unique name, such as "<option name='race'..."
    Then, grab the value from the page you POSTed or GETted to: $_POST['race'] (or $_GET['race'])
    My name is Steve, and I'm a super-villian.

  7. #7
    SitePoint Member
    Join Date
    Jul 2003
    Location
    Reno NV
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    See thats just it, I don't want to post or get, I want the item I selected in the drop down to trigger the next drop down

  8. #8
    La la la la la bronze trophy lieut_data's Avatar
    Join Date
    Jun 2003
    Location
    Waterloo, ON
    Posts
    1,517
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Then you will need to store all the possible drop down values into a javscript array, parsed by PHP, and sort through them based on the selection in the first drop down. (Or, as stated above, trigger a second frame to refresh that reloads the contents of that second combo box)

    Either way, besides the PHP output code, the only solution for client-side interactivity is a client-side language.
    My name is Steve, and I'm a super-villian.

  9. #9
    SitePoint Member
    Join Date
    Jul 2003
    Location
    Reno NV
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    And this is done how? As I mentioned earlier I am a hewbie to java,javascript and PHP. If you want something written in Assembly, pascal, basic, NO problem.

  10. #10
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    A bit of a problem folks ? Umm... Then maybe this link will shed some light for you...

    http://www.sitepointforums.com/showt...hreadid=116384


  11. #11
    SitePoint Member
    Join Date
    Jul 2003
    Location
    Reno NV
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    More of the same PLEASE HELP! (going crazy)

    Ok here is what I have:
    1 Database, 3 Tables: Race, Class, RaceClass.

    Race and Class have 15 entries each and 2 fields:

    Race.............. id ************ Class...............id
    _______________ ************ _________________
    Barbarian ----- 1 ************ Bard ----------- 1
    Dark Elf ------ 2 ************ Beastlord ------ 2
    Dwarf -------- 3 ************ Cleric ---------- 3

    Etc...

    TABLES ARE:
    PHP Code:
    mysql_select_db($database_Iron$Iron);
    $query_race "SELECT * FROM racelist";
    $race mysql_query($query_race$Iron) or die(mysql_error());
    $row_race mysql_fetch_assoc($race);
    $totalRows_race mysql_num_rows($race);

    mysql_select_db($database_Iron$Iron);
    $query_class "SELECT * FROM classlist";
    $class mysql_query($query_class$Iron) or die(mysql_error());
    $row_class mysql_fetch_assoc($class);
    $totalRows_class mysql_num_rows($class); 
    The third table is my JOINING table and has 2 fields and is something like:

    Race ***** Class
    _____**** ____
    1 ----------- 1
    1 ----------- 3
    2 ----------- 1
    2 ----------- 2
    3 ----------- 1
    3 ----------- 3

    A Barbarian can be a Bard or a Cleric BUT NOT a Beastlord
    A Dark Elf can be a Bard or a Beastlord BUT NOT a Cleric
    A Dwarf can be a Bard or Cleric BUT NOT a Beastlord
    PHP Code:
    SELECT classlist.class FROM ((racelist INNER JOIN RaceClass ON racelist.id RaceClass.race) ) INNER JOIN classlist ON RaceClass.class = classlist.id 

    Now to the problems/questions

    I am VERY NEW at web page programming and have really no idea where to start. I am trying to do what this other guy has been asking about.

    I need to have the user Select the RACE,
    PHP Code:

    <form action="" method="get">
    <form name="My Form">
      <select name="Race" >
      <option value="">Select Race</option>
      <?php
    do {  
    ?>
      <option value="<?php echo $row_race['id']?>"><?php echo $row_race['race']?></option>
      <?php
    } while ($row_race mysql_fetch_assoc($race));
      
    $rows mysql_num_rows($race);
      if(
    $rows 0) {
          
    mysql_data_seek($race0);
          
    $row_race mysql_fetch_assoc($race);
      }
    ?>
      </select>
    and based on the 'race' I need the appropriate CLASSES to fill my second list, as you can see it is a MANY TO MANY connection as any selected race may be 1 to 15 of a certain class and vis a vis any certain class might be a particular race

    This don't work correctly
    PHP Code:

     <select name="Class">
      <option value="" <?php if (!(strcmp(""$row_race['id']))) {echo "SELECTED";} ?>>Select
      Class</option>
      <?php
    do {  
    ?>
      <option value="<?php echo $row_class['class']?>"<?php if (!(strcmp($row_class['id'], $row_race['id']))) {echo "SELECTED";} ?>><?php echo $row_class['class']?></option>
      <?php
    } while ($row_class mysql_fetch_assoc($class));
      
    $rows mysql_num_rows($class);
      if(
    $rows 0) {
          
    mysql_data_seek($class0);
          
    $row_class mysql_fetch_assoc($class);
      }
    ?>
      </select>
    </form>
    </form>
    after the class is selected I need to take both values(variables) and assign them to a USER table Variable so I can write them and all the other USER information to the user table.

    I can get the first list to fill in just fine but I can't seem to figure out what I need to pass to the second list to get the correct values to show and have NO IDEA in the world how to work with Variables in a web document. I am not against being pointed in the right direction on where to read how to work with variables if you think it is below you to explain but please help with this, I have been trying to figure it out for about a week andf I am LOSING sleep and GOING CRAZY!!


    P.S.
    Sorry about all the dashes and astrics(sp?) but I could not get this to format without them.

    P.S.S
    I am using DW-MX[PHP]
    Last edited by Cmos; Jul 13, 2003 at 09:15.


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
  •