Jump to content

File not being included


fife

Recommended Posts

Ok im sorry if this is not AJAX as im not too sure if it is.

 

Basically Im trying to make duel select lists.  this is different code from my previous post as no one answered so i had to find a different solution.  So here it goes

 

I have a query that poplulates the first drop down list.

 


//header
function createoptions($table , $id , $field)
{
    $sql = "select * FROM $table ORDER BY $field";
    $res = mysql_query($sql) or die(mysql_error());
    while ($a = mysql_fetch_assoc($res))
    echo "<option value=\"{$a[$id]}\">$a[$field]</option>";
}

//body in a form
<select name="networks"  id="networks">
           <?php  createoptions("networks", "idnetworks", "netname");   ?> 
      </select>

 

next I have another field

<select name="folder" id="folder">
     
    </select>

 

Now in a different page called select.php I have this query

 

<?php
include('../Connections/db.php'); 
session_start();


function createoptions($table , $id , $field , $condition_field , $value)
{
    $sql = sprintf("select * from $table WHERE $condition_field=%s AND type='1' ORDER BY $field" , $value);
    $res = mysql_query($sql) or die(mysql_error());
    if (mysql_num_rows($res) > 0) {
        while ($a = mysql_fetch_assoc($res))
        $out[] = "{optionValue: {$a[$id]}, optionDisplay: '$a[$field]'}";
        return "[" . implode("," , $out) . "]";
    } else

        return "[{optionValue: -1 , optionDisplay: 'No result'}]";
}

if (isset($_GET['networks'])) {
    echo createoptions("documents" , "iddocs" , "documentname" , "parentid" , $_GET['networks']);
}


die();
?>

 

Now back on the page with the form I call this query through the following code in the header

 

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript" charset="utf-8">
            $(function(){
              $("select#networks").change(function(){
                $.getJSON("select.php",{networks: $(this).val(), ajax: 'true'}, function(j){
                  var options = '';
                  for (var i = 0; i < j.length; i++) {
                    options += '<option value="' + j[i].optionValue + '">' + j[i].optionDisplay + '</option>';
                  }
                  $("select#folder").html(options);
                })
              })
            })
            </script>

 

Now the second list is show as completely blank.  Im not too sure how to trouble shoot this issue or even where to start.  Can some please help

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.