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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Oct 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question from a newbie

    Heres my problem:
    Ive three drop down boxes on this form that I want to populate dynamically.
    The first populates fine.
    The second doesnt populate at all.
    The third shows everything and doesnt take user choices into account.
    Im at my wits end trying to figure this out.

    Here's my code:

    <?php


    $dbservertype='mysql';
    $servername='localhost';
    // username and password to log onto db server
    $dbusername='root';
    $dbpassword='01046993';
    // name of database
    $dbname='library';

    ////////////////////////////////////////
    ////// DONOT EDIT BELOW /////////
    ///////////////////////////////////////
    connecttodb($servername,$dbname,$dbusername,$dbpassword);
    function connecttodb($servername,$dbname,$dbuser,$dbpassword)
    {
    global $link;
    $link=mysql_connect ("$servername","$dbuser","$dbpassword");
    if(!$link){die("Could not connect to MySQL");}
    mysql_select_db("$dbname",$link) or die ("could not open db".mysql_error());
    }
    ?>

    <!doctype html public "-//w3c//dtd html 3.2//en">

    <html>

    <head>
    <title>Upload screen attempt</title>
    <meta name="GENERATOR" content="Arachnophilia 4.0">
    <meta name="FORMATTER" content="Arachnophilia 4.0">
    <SCRIPT language=JavaScript>
    function reload(form)
    {
    var val=form.Style.options[form.Style.options.selectedIndex].value;
    self.location='dd3.php?Style=' + val ;
    }
    function reload3(form)
    {
    var val=form.Style.options[form.Style.options.selectedIndex].value;
    var val2=form.classifications.options[form.classifications.options.selectedIndex].value;

    self.location='dd3.php?Style=' + val + '&Item_Type=' + val2 ;
    }

    </script>
    </head>

    <body>
    <?


    ///////// Getting the data from Mysql table for first list box//////////
    $quer2=mysql_query("SELECT DISTINCT ID,Name FROM Styles");
    ///////////// End of query for first list box////////////

    /////// for second drop down list we will check if category is selected else we will display all the subcategory/////
    $Style=$HTTP_GET_VARS['Style']; // This line is added to take care if your global variable is off
    if(isset($Style)){
    $quer=mysql_query("SELECT DISTINCT ID,Name FROM classifications where ID=$Style");
    }else{$quer=mysql_query("SELECT DISTINCT ID,Name FROM classifications"); }
    ////////// end of query for second subcategory drop down list box ///////////////////////////


    /////// for Third drop down list we will check if sub category is selected else we will display all the subcategory3/////
    $Item_Type=$HTTP_GET_VARS['Item_Type']; // This line is added to take care if your global variable is off
    if(isset($Item_Type)){
    $quer3=mysql_query("SELECT DISTINCT Name FROM Item_Types where ID=$Item_Type");
    }else{$quer3=mysql_query("SELECT DISTINCT Name FROM Item_Types"); }
    ////////// end of query for third subcategory drop down list box ///////////////////////////

    echo "<form method=post name=Upload attempt action=''>";
    ////////// Starting of first drop downlist /////////
    echo "<select name='Style' onchange=\"reload(this.form)\"><option value=''>Select one</option>";
    while($noticia2 = mysql_fetch_array($quer2)) {
    if($noticia2['ID']==@$Style){echo "<option selected value='$noticia2[ID]'>$noticia2[Name]</option>"."<BR>";}
    else{echo "<option value='$noticia2[ID]'>$noticia2[Name]</option>";}
    }
    echo "</select>";
    ////////////////// This will end the first drop down list ///////////



    ////////// Starting of second drop downlist /////////
    echo "<select name='classifications' onchange=\"reload3(this.form)\"><option value=''>Select one</option>";
    while($noticia = mysql_fetch_array($quer)) {
    if($noticia['ID']==@$Item_Type){
    echo "<option selected value='$noticia[ID]'>$noticia[classifications]</option>"."<BR>";
    }else{
    echo "<option value='$noticia[Name]'>$noticia[classifications]</option>";
    }
    }
    echo "</select>";
    ////////////////// This will end the second drop down list ///////////



    ////////// Starting of third drop downlist /////////
    echo "<select name='Item_Type' ><option value=''>Select one</option>";
    while($noticia = mysql_fetch_array($quer3)) {
    echo "<option value='$noticia[Name]'>$noticia[Name]</option>";
    }
    echo "</select>";
    ////////////////// This will end the third drop down list ///////////

    echo $noticia['ID'];
    echo $noticia2['ID'];
    echo "</form>";
    ?>
    <center><a href='http://www.mcnallydesign.com'></a></center>
    </body>

    </html>

  • #2
    Regular Coder
    Join Date
    Oct 2004
    Location
    London E4 UK
    Posts
    320
    Thanks
    0
    Thanked 0 Times in 0 Posts
    way beyond me but this is defo out there on google

    plenty of people have struggled with this and won, involves arrays and javascript as I recall


  •  

    Posting Permissions

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