Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Mar 2007
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Real time listbox update

    I have one listbox that I populate with

    PHP Code:
    while($row mysql_fetch_array($resultMYSQL_ASSOC
    I need to in real time populate another listbox from a related table based on what they have currently selected in the first listbox.

    Is this possible with php and if so.. some pointers would be nice.

    Thanks

  • #2
    New Coder
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    91
    Thanks
    21
    Thanked 0 Times in 0 Posts
    I think with some help of javascript this will be possible, although, no pointers here.
    Thank you for your time to read my post

  • #3
    Regular Coder the-dream's Avatar
    Join Date
    Mar 2007
    Location
    Northamptonshire, UK
    Posts
    477
    Thanks
    8
    Thanked 4 Times in 4 Posts
    Refresh the page every second.

    Tip: Create a JavaScript so you dont get a flicker!

  • #4
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    Since you mention realtime, you'd have to use AJAX here.

    Otherwise you'd have to submit the page every time the dropdown changes.

  • #5
    Super Moderator JohnDubya's Avatar
    Join Date
    Nov 2006
    Location
    Missouri
    Posts
    634
    Thanks
    12
    Thanked 18 Times in 18 Posts
    rschoenbach, here's a link to a site that describes how to dynamically fill select boxes with pre-fetched values.

    http://www.petenelson.com/aspwatch/A...ct%20Lists.htm

    You can use mysql_query(), mysql_fetch_array(), and while() loops to grab the values that need to fill the select boxes. It's a bit complicated at first, but once you stare at it for hours like I did, it will become clear...hopefully. If you need help integrating the PHP code, let me know, and I'll try to help. I can at least show you how I did it.

    [EDIT] Just to give you a start, I'll give you a hint of how to fill up the select box. So if your first select box (SportsList) equals 1:

    PHP Code:
    if (SportsList[SportsList.selectedIndex].value == "1") {
          
    AddToOptionList(document.frmMain.Teams"1""Oakland Athletics");
          
    AddToOptionList(document.frmMain.Teams"2""San Francisco Giants");

    It puts in the two options above. But you can just use PHP/MySQL to grab info from your DB and throw the info into these AddToOptionList entries:

    PHP Code:
    if (SportsList[SportsList.selectedIndex].value == "1") {

       
    $x mysql_query("SELECT id, name FROM teams WHERE category_id = '1'");

       while (
    $y mysql_fetch_array($x)) {
          
    $id $y['id'];
          
    $name $y['name'];

          echo 
    'AddToOptionList(document.frmMain.Teams, "' $id '", "'$name .");
       }

    That should at least get you started. Cheers!
    Last edited by JohnDubya; 03-14-2007 at 05:12 PM.

  • #6
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,049
    Thanks
    2
    Thanked 317 Times in 309 Posts
    Here is a current thread on how to do this using AJAX - a selection in a list to populate another list on the same form
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.


  •  

    Posting Permissions

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