Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2003
    Location
    england
    Posts
    95

    Unanswered: Populating a Drop down box from the results of another!

    me again, last problem i swear.

    i have a html form with a dropdown box the contents of which are pulled back from a DB(in this case a list of all students first names in the student table)
    i want to be able to click a name from a list and then automatically have the second drop down box populated with all surnames matching the first name selected in the first box, is this possible at all because i cant seem to find an answer.

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    theoretically yes, however its not really an SQL question, its more to do with your front end.

    To maximise the chances of a response it may help if you say what SQL product (& version) adb what you are using to generate the HTML (eg ASP, PHP, Perl/CGI etc..)
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Nov 2003
    Location
    england
    Posts
    95
    ok i have changed the way i want to do things but i still need a tiny bit of code to help me, basically i concatenated the two string so that both names display in one drop down box, what i need to do now is to split the two selected names up so that i can use them to select the specific record from the db. This is the code i currently have

    $dbh=mysql_connect ("localhost", "twqwwsoy_user", "iiyama") or die ('I cannot connect to the database because: ' . mysql_error());
    mysql_select_db ("twqwwsoy_resources");

    echo "<select name='studentname'>";

    $query = "SELECT first_name,surname FROM Student WHERE 1";

    $result = mysql_query($query);
    $NoR = mysql_numrows($result);
    While ($i < $NoR){
    $name = mysql_result($result,$i,"first_name");
    $name .= " ";
    $name .= mysql_result($result,$i,"surname");
    echo "<option>$name</option>";
    $i++;
    }
    ?>

  4. #4
    Join Date
    Apr 2005
    Location
    Baltimore, MD
    Posts
    297
    explode will split the string.

Posting Permissions

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