Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jul 2007
    Velsen Noord, Netherlands
    Thanked 0 Times in 0 Posts

    Depending dropdownmenus with mysql database

    I have a problem and searched a lot on internet but haven't found the right solution for it. I found ajax but the one I found was hard coded and not from the database.

    Here is my problem:

    I have 2 dropdownmenu's, the second depending on the selection of the first. After the select of the second is also made an id from the database (linked to the second) is shown in a text field.

    The code I already have can show the first dropdown filled but to refresh and fill the second I dont have yet (probably javascript, but dont know how).

    Here is the code I have:
    PHP Code:
    // open connection to MySQL server 
    $connection mysql_connect('localhost''hgdhhgd''password'
            or die (
    'Unable to connect!'); 
    //select database 
    mysql_select_db('bestellingen') or die ('Unable to select database!'); 
    $sql 'SELECT * FROM hesk_programma ORDER BY Programma ASC'
    $result mysql_Query($sql) or die ('Error in query: $query. ' mysql_error()); 

    $menuContent2 ''$menuArray2 ''
      while ( 
    $row mysql_fetch_array$result ) ) { 
    $menuArray2    .= "      dArray['$row[Programma]'];\n"
    $menuContent2 .= "        <option value=\"$row[Programma_id]\">$row[Programma]</option>\n"
       if( isset(
    $_POST['Programma_id']) ){ 
    $query 'SELECT * FROM hesk_projecten WHERE `Project_id` = \''.mysql_real_escape_string($_POST['Programma_id']).'\''
    $result mysql_Query($sql) or die ('Error in query: $query. ' mysql_error()); 

    $menuContent1 ''$menuArray1 ''
      while ( 
    $row mysql_fetch_array$result ) ) { 
    $menuArray1    .= "      dArray['$row[Project]'];\n"
    $menuContent1 .= "        <option value=\"$row[Project_id]\">$row[Project]</option>\n"
    <select id="nameid2" name="name2">         
            <option name="select name2" value="select name2">Selecteer leverancier</option>         
            <?PHP echo $menuContent2?>       

    <select id="nameid1" name="name1">         
            <option name="select name1" value="select name1">Selecteer leverancier</option>         
            <?PHP echo $menuContent1?>       

    <name="projectnum" id="projectnum" size="20" value="<?php echo stripslashes(hesk_input($_SESSION['c_projectnum']));?>">
    Any help would be great.

  2. #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Thanked 637 Times in 625 Posts
    Are you open to using jQuery? There is a very elegant plugin that handles this all for you, if you want to give it a shot.



Posting Permissions

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