Select box help

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

    Select box help

    All,

    I have a problem that I'm not quite sure what algorithm will help me on. I'm
    bringing in records from MySQL using PHP and need to spit this records into
    a select box. Fairly simple, here's my code for the first select box:

    <option selected
    value="<?=$curr entCatID?>"><?= $currentCategor yName?><option>
    <?php
    while($rowGetCa t = mysql_fetch_arr ay($resultGetCa t)){
    if($rowGetCat['pCatID'] != $currentCatID){
    echo "<option
    value=\"".$rowG etCat['pCatID']."\">".$rowGetC at['pCatName']."</option>";
    }
    }
    ?>
    </select>

    Problem is - based on their choice with the first select box, I need to
    query the DB and populate a second select box. So basically, I need a 2nd
    select box that is populated on the fly based on their choice from the first
    select box. The only solutions I have found so far use their own form, and
    the form I have now has numerous other options and values that I need to
    save the state of for editing.

    I was thinking AJAX might help, or maybe just regular javascript, but
    without having the entire page reload I'm not sure. Any ideas?


  • Regenuluz

    #2
    Re: Select box help

    I'm pretty sure AJAX would be the best choice here.
    And the only one I can think of, where you don't have to reload the
    entire page.

    Comment

    • Andy Jeffries

      #3
      Re: Select box help

      On Tue, 02 May 2006 13:47:08 -0700, Regenuluz wrote:[color=blue]
      > I'm pretty sure AJAX would be the best choice here. And the only one I can
      > think of, where you don't have to reload the entire page.[/color]

      You could also use a regular Javascript data structure within <script>
      tags dynamically printed/echoed using PHP, then filter the data structure
      using Javascript to only display the relevant items.

      However, it could make page weight enormous, so it may not be possible
      with your dataset (plus you may not like the idea of your dataset being
      easily viewable, although anyone can read the AJAX source and pull it
      using a script if they're interested so neither way is secure).

      I do, however, agree with Regenluz that AJAX would be the best solution,
      but in case writing custom AJAX code is out of your realm of abilities,
      there is the way I suggest above.

      Cheers,


      Andy


      --
      Andy Jeffries MBCS CITP ZCE | gPHPEdit Lead Developer
      http://www.gphpedit.org | PHP editor for Gnome 2
      http://www.andyjeffries.co.uk | Personal site and photos

      Comment

      • Jon

        #4
        Re: Select box help


        "Andy Jeffries" <news@andyjeffr ies.co.uk> wrote in message
        news:pan.2006.0 5.02.21.42.07.5 05570@andyjeffr ies.co.uk...[color=blue]
        > On Tue, 02 May 2006 13:47:08 -0700, Regenuluz wrote:[color=green]
        >> I'm pretty sure AJAX would be the best choice here. And the only one I
        >> can
        >> think of, where you don't have to reload the entire page.[/color]
        >
        > You could also use a regular Javascript data structure within <script>
        > tags dynamically printed/echoed using PHP, then filter the data structure
        > using Javascript to only display the relevant items.
        >
        > However, it could make page weight enormous, so it may not be possible
        > with your dataset (plus you may not like the idea of your dataset being
        > easily viewable, although anyone can read the AJAX source and pull it
        > using a script if they're interested so neither way is secure).
        >
        > I do, however, agree with Regenluz that AJAX would be the best solution,
        > but in case writing custom AJAX code is out of your realm of abilities,
        > there is the way I suggest above.
        >
        > Cheers,
        >
        >
        > Andy
        >
        >
        > --
        > Andy Jeffries MBCS CITP ZCE | gPHPEdit Lead Developer
        > http://www.gphpedit.org | PHP editor for Gnome 2
        > http://www.andyjeffries.co.uk | Personal site and photos
        >[/color]

        Yeah, that's definitely an option I considered - Bringing in all of the
        subcategories and running a case on the onchange event using the value
        they've passed in. But like you said, it makes the page pretty heavy having
        to bring in this data - plus, I need this same process to be run on a few
        different pages - and many times users aren't going to be updating the
        categories, so I just need them to stay the same but still be available.

        Looks like my options are down to: AJAX, making the category options a
        separate form/choice, or weighting my page down.

        AJAX might be out of my realm unfortunately - We do have some books, and I'm
        confident in my code, but I've never written any real-world stuff and I have
        until June 1 to have this project completed. Thanks for the info guys. If
        anyone else has suggestions, I'm always open :)


        Comment

        • Andy Jeffries

          #5
          Re: Select box help

          On Tue, 02 May 2006 16:55:30 -0500, Jon wrote:[color=blue]
          > AJAX might be out of my realm unfortunately - We do have some books, and
          > I'm confident in my code, but I've never written any real-world stuff and
          > I have until June 1 to have this project completed. Thanks for the info
          > guys. If anyone else has suggestions, I'm always open :)[/color]

          I've got some fairly simple AJAX javascript functions and can give you
          some advice on it, but it's OT on this group. Feel free to email me if
          you like, I can give you some code to get you started with AJAX and
          then help you implement it if you like*... Use my first name at
          andyjeffries dot co dot uk.

          * I'd love to offer to really get my hands dirty and help implement it for
          you, but I really don't have time. However, I'll happily send you code
          snippets for the AJAX stuff and help with explanations however I can.

          Cheers,


          Andy


          --
          Andy Jeffries MBCS CITP ZCE | gPHPEdit Lead Developer
          http://www.gphpedit.org | PHP editor for Gnome 2
          http://www.andyjeffries.co.uk | Personal site and photos

          Comment

          • william.clarke@gmail.com

            #6
            Re: Select box help

            Ajax would work fine for this, but why not reload the page (if you
            haven't used AJAX) and store any previous data entered and redisplay it
            when the second list is filled, that works fine and the user experience
            shouldn't be badly effected, unless you have a very large/complicated
            page.

            Comment

            • Andy Jeffries

              #7
              Re: Select box help

              On Wed, 03 May 2006 15:11:27 -0700, william.clarke@ gmail.com wrote:[color=blue]
              > Ajax would work fine for this, but why not reload the page (if you haven't
              > used AJAX) and store any previous data entered and redisplay it when the
              > second list is filled, that works fine and the user experience shouldn't
              > be badly effected, unless you have a very large/complicated page.[/color]

              Because AJAX really isn't that difficult for a competant programmer. Your
              method should be used as a backup plan if AJAX isn't available
              (feature-test for it and if it's available hide the button that submits
              the form with the first drop down filled in).

              Cheers,


              Andy

              --
              Andy Jeffries MBCS CITP ZCE | gPHPEdit Lead Developer
              http://www.gphpedit.org | PHP editor for Gnome 2
              http://www.andyjeffries.co.uk | Personal site and photos

              Comment

              Working...