doublecombo form

Discussion in 'PHP' started by neptun221, Jan 18, 2010.

  1. #1
    Hi,

    I would like to create a kind of double menu (form) that you can choose a continent in first box and in second a country. OnClick it should do the query on mysql database and give the result. I was wondering if it is possible that it calls a function and not a web page. this is what I have:

    <?php

    function myquery(){

    $con = mysql_connect("dmc04.sst.co.uk","guest","kasia");
    if (!$con)
    {
    die('Could not connect: ' . mysql_error());
    }

    mysql_select_db("mydb", $con);

    $result = mysql_query("SELECT id FROM cat_image c where oid in (select image from cat_tagref c where tag = 246)");

    while($row = mysql_fetch_array($result))
    {
    echo $row['id'];
    echo "<br />";
    }
    }
    ?>



    <form name="doublecombo">
    <p><select name="example" size="1" onChange="redirect(this.options.selectedIndex)">
    <option>Asia</option>
    <option>Australia</option>
    <option>North America</option>
    <option>Europe</option>
    <option>South America</option>

    </select>
    <select name="stage2" size="1">
    <option value= "china.php">China</option>
    <option value="indonesia.php">Indonesia</option>
    <option value="afghanistan.php">Afghanistan</option>
    <option value="pakistan.php">Pakistan</option>
    <option value="siria.php">Siria</option>
    <option value="oman.php">Oman</option>


    </select>
    <input type="button" name="test" value="Go!"
    onClick="go()" >
    </p>

    <script>

    <!--

    /*
    Double Combo Script Credit
    By Website Abstraction (www.wsabstract.com)
    Over 200+ free JavaScripts here!
    */



    var groups=document.doublecombo.example.options.length
    var group=new Array(groups)
    for (i=0; i<groups; i++)
    group=new Array()

    group[0][0]=new Option("China","http://www.china.php")
    group[0][1]=new Option("Indonesia","http://www.indonesia.php")

    group[1][0]=new Option("Australia","http://www.australia.php")
    group[1][1]=new Option("New Zeland","http://www.newzeland.php")

    group[2][0]=new Option("Salvador","salvador.php")
    group[2][1]=new Option("Cuba","http://www.cuba.php")


    group[3][0]=new Option("Canada","http://www.lycos.com")
    group[3][1]=new Option("Canada","http://www.lycos.com")
    group[3][2]=new Option("Canada","http://www.lycos.com")
    group[3][3]=new Option("Canada","http://www.lycos.com")
    group[3][4]=new Option("Canada","http://www.lycos.com")

    group[4][0]=new Option("Canada","http://www.lycos.com")
    group[4][1]=new Option("Canada","http://www.lycos.com")
    group[4][2]=new Option("Canada","http://www.lycos.com")
    group[4][3]=new Option("Canada","http://www.lycos.com")
    group[4][4]=new Option("Canada","http://www.lycos.com")

    var temp=document.doublecombo.stage2

    function redirect(x){
    for (m=temp.options.length-1;m>0;m--)
    temp.options[m]=null
    for (i=0;i<group[x].length;i++){
    temp.options=new Option(group[x].text,group[x].value)
    }
    temp.options[0].selected=true
    }

    function go(){
    location=temp.options[temp.selectedIndex].value
    }
    //-->
    </script>




    So instead of connecting to ex. china.php, I would like that it does the function myquery().
    Or it's impossible?
    Maybe somebody has different idea, how to achive what I want?

    I would appreciate every answer. As I am a new with php, please try to explain it in steps. thx

    Kasia
     
    neptun221, Jan 18, 2010 IP
  2. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #2
    This is mostly a Javascript question. Your Javascript needs to send a request to the URL for the PHP program that provides the values for the country list.
     
    SmallPotatoes, Jan 20, 2010 IP