Select statement using a second select statement from same input page to gather info

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • micky125
    New Member
    • Sep 2008
    • 36

    Select statement using a second select statement from same input page to gather info

    Hey guys I have been checking the forum for a way to populate a second select field depending on the choice made from the first one. Basically i am working on projects and the delays that occur. The first select is project and i am asking user to select it by using

    Code:
    <?php
              $sql = "SELECT ProjectName
                      FROM   ProjectDetails";
                     "ORDER BY ProjectName";
                    $rs = mysql_query($sql);
                    while($row = mysql_fetch_array($rs))
                    {
                      echo "<option value=\"".$row['ProjectName']."\">";
                    }
    ?>
    then for my second select statement i want it to be populated by using

    Code:
    <?php
                    $sql = "SELECT Task
                            FROM   Delay
                            WHERE  ProjectName = (the problem) ".
                           "ORDER BY Task";
                    $rs = mysql_query($sql);
                    while($row = mysql_fetch_array($rs))
                    {
                      echo "<option value=\"".$row['Task']."\">";
                    }
    ?>
    I have seen a forum that says to use AJAX (http://bytes.com/forum/thread790663.html) but i dont have enough time to learn this. Is it possible to call the result found from the first select as a variable so i can then use it in the second query? where (the problem) = var1?

    Any1 any ideas on this?
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    If you don't want a page refresh, you're going to have to learn AJAX (It seriously takes no longer than 1 hour to learn.) Otherwise, you will have to submit the dropdown list to the same page (as a form - using GET possibly) and then $_GET the selected projectName and use this in your second WHERE clause to show the related projects.

    Comment

    • micky125
      New Member
      • Sep 2008
      • 36

      #3
      thanks for the quick reply appreciated. Ill have another look at some tutorials on AJAX if u say it easy to understand. Thanks for clarifying it.

      Comment

      • Markus
        Recognized Expert Expert
        • Jun 2007
        • 6092

        #4
        Originally posted by micky125
        thanks for the quick reply appreciated. Ill have another look at some tutorials on AJAX if u say it easy to understand. Thanks for clarifying it.
        No problem. Once you've had a go, post the code you used (if you have a problem with it) and we'll give you more help!

        Comment

        Working...