SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru
    Join Date
    Oct 2004
    Location
    uk
    Posts
    853
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    call values from database

    Hi guys

    I have used this script to call locations the problem is it calls the locations from the file and I want to call them from the database

    How can i edit this file to call them from the database?

    example.php

    PHP Code:
    <script type="text/javascript" src="http://www.notexperienced.co.uk/employers/js/default.aspx?prx=http://www.dhtmlgoodies.com/ajax.js"></script>
    <script type="text/javascript">
        
    var ajax = new sack();

    function getCityList(sel)
    {
        var countryCode = sel.options[sel.selectedIndex].value;
        document.getElementById('dhtmlgoodies_city').options.length = 0;    // Empty city select box
        if(countryCode.length>0){
            ajax.requestFile = 'getCities.php?countryCode='+countryCode;    // Specifying which file to get
            ajax.onCompletion = createCities;    // Specify function that will be executed after file has been found
            ajax.runAJAX();        // Execute AJAX function
        }
    }

    function createCities()
    {
        var obj = document.getElementById('dhtmlgoodies_city');
        eval(ajax.response);    // Executing the response from Ajax as Javascript code    
    }

            
    </script>

    <form action="" method="post">
    <table>
        <tr>
            <td>Country: </td>
            <td><select id="dhtmlgoodies_country" name="dhtmlgoodies_country" onchange="getCityList(this)">
                <option value="">Select</option>
                <option value="dk">Denmark</option>
                <option value="no">Norway</option>
                <option value="us">US</option>
            </select>
            </td>
        </tr>
        <tr>
            <td>City: </td>
            <td><select id="dhtmlgoodies_city" name="dhtmlgoodies_city">
            
            </select>
            </td>
        </tr>
    </table> 


    getCities.php

    PHP Code:
    <?php

    if(isset($_GET['countryCode'])){
      
      switch(
    $_GET['countryCode']){
        
        case 
    "no":
          echo 
    "obj.options[obj.options.length] = new Option('Bergen','1');\n";
          echo 
    "obj.options[obj.options.length] = new Option('Haugesund','2');\n";
          echo 
    "obj.options[obj.options.length] = new Option('Oslo','3');\n";
          echo 
    "obj.options[obj.options.length] = new Option('Stavanger','4');\n";
          
          break;
        case 
    "dk":
          
          echo 
    "obj.options[obj.options.length] = new Option('Aalborg','11');\n";
          echo 
    "obj.options[obj.options.length] = new Option('Copenhagen','12');\n";
          echo 
    "obj.options[obj.options.length] = new Option('Odense','13');\n";
          
          break;
        case 
    "us":
          
          echo 
    "obj.options[obj.options.length] = new Option('Atlanta','21');\n";
          echo 
    "obj.options[obj.options.length] = new Option('Chicago','22');\n";
          echo 
    "obj.options[obj.options.length] = new Option('Denver','23');\n";
          echo 
    "obj.options[obj.options.length] = new Option('Los Angeles','24');\n";
          echo 
    "obj.options[obj.options.length] = new Option('New York','25');\n";
          echo 
    "obj.options[obj.options.length] = new Option('San Fransisco','26');\n";
          echo 
    "obj.options[obj.options.length] = new Option('Seattle','27');\n";
          
          break;
      }  
    }

    ?>

  2. #2
    Caveat surfer Buddy Bradley's Avatar
    Join Date
    May 2003
    Location
    Cambridge, UK
    Posts
    2,366
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You need to know about using MySQL.

  3. #3
    SitePoint Guru
    Join Date
    Oct 2004
    Location
    uk
    Posts
    853
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    of course i know about mysql, i want to know how to intergrate my current database which is set up

    I have a (category) and (subcategory) tables, These are linked together via a cat_id number

    This is what I want to put into the dropdown menus

    I have already done this in java but the page has to refresh to get the values

    Im using ajax so that it calls the sublocations without refreshing the page.


    This is my script I was currently using

    PHP Code:






    <?
     $cat
    =$_POST['location'];
    $subcat=$_POST['sublocation'];
    /*
    If register_global is off in your server then after reloading of the page to get the value of cat from query string we have to take special care.
    To read more on register_global visit.
      http://www.plus2net.com/php_tutorial/register-globals.php
    */
    @$cat=$_GET['location']; // Use this line or below line if register_global is off
    //@$cat=$HTTP_GET_VARS['location']; // Use this line or above line if register_global is off

    ///////// Getting the data from Mysql table for first list box//////////
    $quer2=mysql_query("SELECT DISTINCT location,cat_id FROM location order by location ASC"); 
    ///////////// 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///// 
    if(isset($cat) and strlen($cat) > 0){



    $quer=mysql_query("SELECT DISTINCT sublocation FROM sublocation where cat_id=$cat order by sublocation"); 
    }else{
    $quer=mysql_query("SELECT DISTINCT sublocation FROM sublocation order by sublocation"); } 
    ////////// end of query for second subcategory drop down list box ///////////////////////////


    /// Add your form processing page address to action in above line. Example  action=dd-check.php////
    //////////        Starting of first drop downlist /////////
    echo "<select name='location' onchange=\"reload(this.form)\">
    <option value=''>------------------------ Please select a Location ---------------------------</option>"
    ;
    while(
    $noticia2 mysql_fetch_array($quer2)) { 
    if(
    $noticia2['cat_id']==@$cat){echo "<option selected value='$noticia2[location]'>$noticia2[location]</option>"."<BR>";}
    else{echo  
    "<option value='$noticia2[cat_id]'>$noticia2[location]</option>";}
    }
    echo 
    "</select></TD></TR><TR><TD><font size=4>Sub Location</td><td>";
    //////////////////  This will end the first drop down list ///////////

    //////////        Starting of second drop downlist /////////
    echo "<select name='sublocation'>
    <option value=''>---------------------- Please select a Sub Location ----------------------</option>"
    ;
    while(
    $noticia mysql_fetch_array($quer)) { 
    echo  
    "<option value='$noticia[sublocation]'>$noticia[sublocation]</option>";
    }
    echo 
    "</select>";
    //////////////////  This will end the second drop down list ///////////


    ?>








    uploader.php

    PHP Code:

    <?




    if($_POST['Submit']){
        if(
    is_uploaded_file($_FILES['file']['tmp_name'])){
            
    $filename basename($_FILES['file']['name']);
            
    $target_folder "./cv/";
            
    $target $target_folder $filename;
            if(
    move_uploaded_file($_FILES['file']['tmp_name'], $target)){
                
    //now store file information in your table
                
                
                
                
    $con mysql_connect("localhost","notexper_two","three");
    if (!
    $con)
      {
      die(
    'Could not connect: ' mysql_error());
      }

    mysql_select_db("notexper_one"$con);


     
    $sql "INSERT INTO CV
             (user_id,filename,uploadedcv)
             VALUES('"
    .$_SESSION['seeker']."','$filename','yes')";



    $query mysql_query($sql,$con) or die('Error: ' mysql_error());


    mysql_close($con);




            }
        }
    }
    ?>


Bookmarks

Posting Permissions

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