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 4 of 4
  1. #1
    Regular Coder
    Join Date
    Aug 2005
    Posts
    145
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Viewing multiple fields in dynamic dropdowns.

    Hi,

    I have the foll code for populating a dropdown based on the results of a selection in a primary dropdown. Problem is that when the 2nd d.d. is loaded, it only shows me the City and not the Province. Now I need to have both the fields appearing on the page so the user makes the correct selection.

    The 2 tables are :

    States with field names SID(int), State(varchar)
    Cities with field names CITYID(int), SID(int), City(varchar) , Province(varchar)


    Would really appreciate if someone could show me how to modify the foll line so that both city,province appear on the users screen in the dropdown box.

    PHP Code:
    echo "<select name='subcat'><option value=''>Select one</option>"
    while(
    $noticia mysql_fetch_array($quer)) { 
    echo 
    "<option value='$noticia[CITYID]'>$noticia[City],$noticia[Province]</option>"

    Thanks.
    PHP Code:
    <? include("protect.php"); ?> // contains all db info 

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

    <html> 

    <head> 
    <title>Multiple drop down list box from plus2net</title> 
    <meta name="GENERATOR" content="Arachnophilia 4.0"> 
    <meta name="FORMATTER" content="Arachnophilia 4.0"> 
    <SCRIPT language=JavaScript> 
    function reload(form) 

    var val=form.cat.options[form.cat.options.selectedIndex].value; 
    self.location='add_custadd1.php?cat=' + val ; 


    </script> 
    </head> 

    <body> 
    <? 


    mysql_connect
    ("localhost"$dbname$dbpasswd ) or die ("Unable to connect to server."); 

    mysql_select_db($database) or die ("Unable to select database."); 


    @
    $cat=$_GET['cat']; 

    $quer2 mysql_query"SELECT DISTINCT `State`, `SID` FROM `States` "); 

    if(isset(
    $cat) and strlen($cat) > 0){ 
    $quer=mysql_query("SELECT DISTINCT `City` FROM `Cities` where `SID`=$cat order by `City`"); 

    }else{
    $quer=mysql_query("SELECT DISTINCT City FROM Cities order by City"); } 

    echo 
    "<form method=post name=f1 action='add_custadd2.php'>"

    echo 
    "<select name='cat' onchange=\"reload(this.form)\"><option value=''>Select one</option>"
    while(
    $noticia2 mysql_fetch_array($quer2)) { 
    if(
    $noticia2['SID']==@$cat){echo "<option selected value='$noticia2[SID]'>$noticia2[State]</option>"."<BR>";} 
    else{echo 
    "<option value='$noticia2[SID]'>$noticia2[State]</option>";} 

    echo 
    "</select>"

    echo 
    "<select name='subcat'><option value=''>Select one</option>"
    while(
    $noticia mysql_fetch_array($quer)) { 
    echo 
    "<option value='$noticia[CITYID]'>$noticia[City],$noticia[Province]</option>";  // THIS STATEMENT ONLY SHOWS CITY AND NOT CITY,PROVINCE. 

    echo 
    "</select>"

    echo 
    "<input type=submit value=Submit>"
    echo 
    "</form>"

    ?> 

    </body> 

    </html>

  • #2
    Regular Coder
    Join Date
    May 2005
    Posts
    563
    Thanks
    0
    Thanked 3 Times in 3 Posts
    You're not selecting province from the table.

    Just change
    PHP Code:
    $quer=mysql_query("SELECT DISTINCT `City` FROM `Cities` where `SID`=$cat order by `City`"); 
    to

    PHP Code:
    $quer=mysql_query("SELECT DISTINCT `City`,`Provnce` FROM `Cities` where `SID`=$cat order by `City`"); 

  • #3
    Regular Coder
    Join Date
    Aug 2005
    Posts
    145
    Thanks
    0
    Thanked 0 Times in 0 Posts
    am afraid didnt help.

    PHP Code:
    $quer=mysql_query("SELECT DISTINCT `City`,`Province` FROM `Cities` where `SID`=$cat order by `City`"); 
    Also changed the foll.

    PHP Code:
    echo "<select name='subcat'><option value=''>Select one</option>";  
    while(
    $noticia mysql_fetch_array($quer)) {  
    echo 
    "<option value='$noticia[City],$noticia[Province]'>$noticia[City],$noticia[Province]</option>"
    I get the city name follwed by the Comma but the province name doesnt pop up.

    Any thing else i could be checking for ?
    Thanks !

  • #4
    Regular Coder
    Join Date
    Aug 2005
    Posts
    145
    Thanks
    0
    Thanked 0 Times in 0 Posts

    *solved*

    Aagh ! Spelling mistake ! Its working now. Thanks SeeIT Solutions !


  •  

    Posting Permissions

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