populate one menu from another

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Chris

    #1

    populate one menu from another

    I thought this would be simple and there would be advice / tutorials
    everywhere for this, but now that I'm working on it, I can't find any
    reference except for ASP or Javascript code. PHP/MySQL - 3 form select
    menus: Project, Categories, Subcategories. When a Project is selected, the
    Categories list is populated based on Project selected, then Subcategories
    list is populated based on Category selected. I see this all over the Net,
    but through 10 books, there isn't anything specific. I think I get lost
    with some of PHP structure since I've been using DW - I end up editing most
    of it in order to follow it, but DW works pretty good for getting initial
    testing done. I just can't seem to find further guidance on this. So far I
    have:

    <form enctype="multip art/form-data" action="add_fil e.php" method="post">
    <table>

    <tr>
    <td width="23%" rowspan="2" valign="top"><p ><strong>Projec t:<br />
    </strong>
    <select name="project">
    <?php
    do {
    ?>
    <option value="<?php echo
    $row_projects['projCode']?>"><?php echo $row_projects['projCode']?></option>
    <?php
    } while ($row_projects = mysql_fetch_ass oc($projects));
    $rows = mysql_num_rows( $projects);
    if($rows 0) {
    mysql_data_seek ($projects, 0);
    $row_projects = mysql_fetch_ass oc($projects);
    }
    ?>
    </select>
    </p>
    <p><strong>
    Category:
    <select name="category" id="category">
    <option>Selec t a category...</option>
    <option value="<?php echo $row_categories['catName']?>"><?php
    echo $row_categories['catName']?></option>
    <?php
    do {
    ?>
    <?php
    } while ($row_categorie s = mysql_fetch_ass oc($categories) );
    $rows = mysql_num_rows( $categories);
    if($rows 0) {
    mysql_data_seek ($categories, 0);
    $row_categories = mysql_fetch_ass oc($categories) ;
    }
    ?>
    </select>

    </strong></p>
    <p>

    </p></td>
    <td width="26%" valign="top"><p ><strong>Subcat egory:</strong>
    <select name="subcatego ry" id="subcategory ">
    <option>Selec t a subcategory...</option>
    <?php
    if (isset('categor y'))
    {
    if ($row_subcat['catID']==$row_categori es['catID'])
    {
    do
    {?>
    <option value="<?php echo $row_subcat['subcatName']; ?>"></option>
    <?php
    }
    while ($row_subcat = mysql_fetch_ass oc($subcat));
    $rows = mysql_num_rows( $subcat);
    if($rows 0)
    {
    mysql_data_seek ($subcat, 0);
    $row_subcat = mysql_fetch_ass oc($subcat);
    }
    }
    }
    }
    ?>
    </select>

    Thanks for any help with this.

    Chris


  • flamer die.spam@hotmail.com

    #2
    Re: populate one menu from another

    Mosf of the examples you have seen are probably using javascript, with
    php you realise the page needs to reload when a cat is chosen? PHP
    can't dynamically update the menu without loading the page again, you
    would the user to choose a catergory, then have a submit button to post
    the var or a link like page/index.php?cat1= $cat1 and so forth. Probably
    recommend javascript for this though.

    Flamer.


    Chris wrote:
    I thought this would be simple and there would be advice / tutorials
    everywhere for this, but now that I'm working on it, I can't find any
    reference except for ASP or Javascript code. PHP/MySQL - 3 form select
    menus: Project, Categories, Subcategories. When a Project is selected, the
    Categories list is populated based on Project selected, then Subcategories
    list is populated based on Category selected. I see this all over the Net,
    but through 10 books, there isn't anything specific. I think I get lost
    with some of PHP structure since I've been using DW - I end up editing most
    of it in order to follow it, but DW works pretty good for getting initial
    testing done. I just can't seem to find further guidance on this. So far I
    have:
    >
    <form enctype="multip art/form-data" action="add_fil e.php" method="post">
    <table>
    >
    <tr>
    <td width="23%" rowspan="2" valign="top"><p ><strong>Projec t:<br />
    </strong>
    <select name="project">
    <?php
    do {
    ?>
    <option value="<?php echo
    $row_projects['projCode']?>"><?php echo $row_projects['projCode']?></option>
    <?php
    } while ($row_projects = mysql_fetch_ass oc($projects));
    $rows = mysql_num_rows( $projects);
    if($rows 0) {
    mysql_data_seek ($projects, 0);
    $row_projects = mysql_fetch_ass oc($projects);
    }
    ?>
    </select>
    </p>
    <p><strong>
    Category:
    <select name="category" id="category">
    <option>Selec t a category...</option>
    <option value="<?php echo $row_categories['catName']?>"><?php
    echo $row_categories['catName']?></option>
    <?php
    do {
    ?>
    <?php
    } while ($row_categorie s = mysql_fetch_ass oc($categories) );
    $rows = mysql_num_rows( $categories);
    if($rows 0) {
    mysql_data_seek ($categories, 0);
    $row_categories = mysql_fetch_ass oc($categories) ;
    }
    ?>
    </select>
    >
    </strong></p>
    <p>
    >
    </p></td>
    <td width="26%" valign="top"><p ><strong>Subcat egory:</strong>
    <select name="subcatego ry" id="subcategory ">
    <option>Selec t a subcategory...</option>
    <?php
    if (isset('categor y'))
    {
    if ($row_subcat['catID']==$row_categori es['catID'])
    {
    do
    {?>
    <option value="<?php echo $row_subcat['subcatName']; ?>"></option>
    <?php
    }
    while ($row_subcat = mysql_fetch_ass oc($subcat));
    $rows = mysql_num_rows( $subcat);
    if($rows 0)
    {
    mysql_data_seek ($subcat, 0);
    $row_subcat = mysql_fetch_ass oc($subcat);
    }
    }
    }
    }
    ?>
    </select>
    >
    Thanks for any help with this.
    >
    Chris

    Comment

    • Jerry Stuckle

      #3
      Re: populate one menu from another

      Gary L. Burnore wrote:
      On 10 Jul 2006 16:13:03 -0700, "flamer die.spam@hotmai l.com"
      <die.spam@hotma il.comtop posted like a moron and wrote:
      >
      >
      >>Mosf of the examples you have seen are probably using javascript, with
      >>php you realise the page needs to reload when a cat is chosen? PHP
      >>can't dynamically update the menu without loading the page again, you
      >>would the user to choose a catergory, then have a submit button to post
      >>the var or a link like page/index.php?cat1= $cat1 and so forth. Probably
      >>recommend javascript for this though.
      >
      >
      The php code can generate the javascript code. Best of both "hello
      worlds".
      >
      >
      >>Flamer.
      And you can generate javascript code without php, also.

      You completely missed the point.


      --
      =============== ===
      Remove the "x" from my email address
      Jerry Stuckle
      JDS Computer Training Corp.
      jstucklex@attgl obal.net
      =============== ===

      Comment

      • Chris

        #4
        Re: populate one menu from another

        Hi All,

        I did find several Javascript-based sets of code, but knew I need something
        where the JS controls the element but had no 'static' variables or arrays .
        One of them has Javascript refresh the page, and another keeps the
        visibility off of secondary listboxes until the primary one is selected. I
        think I will try this one as the <optionscan be populated with PHP, then
        the Javascript/CSS controls when they appear. I did this with a cascading
        menu - where the JS/CSS only controlled the element (byID) and it worked
        fine. If this works out, I will post the final code here.

        Thanks,
        Christina

        "Jerry Stuckle" <jstucklex@attg lobal.netwrote in message
        news:MpKdnXn-qof3kC7ZnZ2dnUV Z_rqdnZ2d@comca st.com...
        Gary L. Burnore wrote:
        >On 10 Jul 2006 16:13:03 -0700, "flamer die.spam@hotmai l.com"
        ><die.spam@hotm ail.comtop posted like a moron and wrote:
        >>
        >>
        >>>Mosf of the examples you have seen are probably using javascript, with
        >>>php you realise the page needs to reload when a cat is chosen? PHP
        >>>can't dynamically update the menu without loading the page again, you
        >>>would the user to choose a catergory, then have a submit button to post
        >>>the var or a link like page/index.php?cat1= $cat1 and so forth. Probably
        >>>recommend javascript for this though.
        >>
        >>
        >The php code can generate the javascript code. Best of both "hello
        >worlds".
        >>
        >>
        >>>Flamer.
        >
        And you can generate javascript code without php, also.
        >
        You completely missed the point.
        >
        >
        --
        =============== ===
        Remove the "x" from my email address
        Jerry Stuckle
        JDS Computer Training Corp.
        jstucklex@attgl obal.net
        =============== ===

        Comment

        • frothpoker

          #5
          Re: populate one menu from another

          I have faced exactly the same problem:

          Chose a region,then a county then a district...

          Two choices with PHP without using javascript. First one is to present
          each question one at a time and pass the values through the forms which
          is a PITA!

          Second one. Generate a single drop down list that looks like the
          following:-

          ------Primary1
          ---Secondary1
          Tertiary1
          Tertiary2
          Tertiary3
          --Secondary2
          Tertiary4
          Terrary5
          ------Primary2
          ---Secondary3
          Tertiary6
          Tertiary7


          and validate that the user has selected a valid tertiary value before
          processing the form

          If you want my code post a reply here and I will pm you

          Obiron
          Chris wrote:
          Hi All,
          >
          I did find several Javascript-based sets of code, but knew I need something
          where the JS controls the element but had no 'static' variables or arrays .
          One of them has Javascript refresh the page, and another keeps the
          visibility off of secondary listboxes until the primary one is selected. I
          think I will try this one as the <optionscan be populated with PHP, then
          the Javascript/CSS controls when they appear. I did this with a cascading
          menu - where the JS/CSS only controlled the element (byID) and it worked
          fine. If this works out, I will post the final code here.
          >
          Thanks,
          Christina
          >
          "Jerry Stuckle" <jstucklex@attg lobal.netwrote in message
          news:MpKdnXn-qof3kC7ZnZ2dnUV Z_rqdnZ2d@comca st.com...
          Gary L. Burnore wrote:
          On 10 Jul 2006 16:13:03 -0700, "flamer die.spam@hotmai l.com"
          <die.spam@hotma il.comtop posted like a moron and wrote:
          >
          >
          >>Mosf of the examples you have seen are probably using javascript, with
          >>php you realise the page needs to reload when a cat is chosen? PHP
          >>can't dynamically update the menu without loading the page again, you
          >>would the user to choose a catergory, then have a submit button to post
          >>the var or a link like page/index.php?cat1= $cat1 and so forth. Probably
          >>recommend javascript for this though.
          >
          >
          The php code can generate the javascript code. Best of both "hello
          worlds".
          >
          >
          >>Flamer.
          And you can generate javascript code without php, also.

          You completely missed the point.


          --
          =============== ===
          Remove the "x" from my email address
          Jerry Stuckle
          JDS Computer Training Corp.
          jstucklex@attgl obal.net
          =============== ===

          Comment

          • Krustov

            #6
            Re: populate one menu from another

            <comp.lang.ph p>
            <frothpoker>
            <12 Jul 2006 06:02:20 -0700>
            <1152709340.794 939.46970@m79g2 000cwm.googlegr oups.com>
            I have faced exactly the same problem:
            >
            Chose a region,then a county then a district...
            >
            Two choices with PHP without using javascript. First one is to present
            each question one at a time and pass the values through the forms which
            is a PITA!
            >
            Second one. Generate a single drop down list
            >
            You could use the ip address and store via a flatfile .

            $skunk=$_SERVER['REMOTE_ADDR'];
            $bjob=str_repla ce(".","_",$sku nk);

            $filename="demo/$bjob" . "_menu.php" ;
            $fp=fopen($file name,"r");
            $qaz=fgets($fp) ; $temp1=trim($qa z);
            fclose($fp);

            $filename="demo/$bjob" . "_demo.php" ;
            $fp=fopen($file name,"r");
            $qaz=fgets($fp) ; $temp1=trim($qa z);
            fclose($fp);

            read/write to suit etc .


            --
            Encrypted email address

            Comment

            Working...