Jump to content

Is SQL correct for this Ajax drop down menu


larsbrimmer

Recommended Posts

I can't find the error in this code. See if you can. 

 

   $data=$_GET['data'];
     $val=$_GET['val'];
     
     //set database
$dbhost = "localhost";
$dbuser = "xx";
$dbpass = "xx";
$dbname    = "xx";
mysql_pconnect($dbhost,$dbuser,$dbpass) or die ("Unable to connect to MySQL server");  
     
     if ($data=='RayMusicCategories') {  // first dropdown
          echo "<select name='Categories' onChange=\"dochange('subcategories', this.value)\">\n";
          echo "<option value='0'>==== choose Category ====</option>\n";
          $result=mysql_db_query($dbname,"select `id`, `title`, `parent` FROM RayMusicCategories WHERE `parent` = '0'");
          while(list($id, $name, $pid)=mysql_fetch_array($result)){
               echo "<option value=\"$id\" >$name</option> \n" ;
          }
     } else if ($data=='RayMusicCategories') { // second dropdown
          echo "<select name='subcategories' >\n";
          echo "<option value='0'>====choose Sub-categories ====</option>\n";                           
          $result=mysql_db_query($dbname,"SELECT `id`, `parent`, `title` FROM RayMusicCategories WHERE `parent` = '$val' ORDER BY `title` ");
          while(list($id, $parent, $name)=mysql_fetch_array($result)){       
               echo "<option value=\"$id\" >$name</option> \n" ;
          }
     } 
     echo "</select>\n"; 

 

Thanks

Other than using depreciated functions

Not sure what this means and what part of the code you are referring to.

 

both your control statements containing the same question

Well the original script used two tables, all my info is in one. How do I fix this.

 

How about you telling us what is wrong,

The example script I have works. I plugged my info into it and the menus don't propagate.

 

Here is the other file that goes with it.

 

<?     
     echo "<form name=sel>\n";
     echo "Categories : <font id=categories><select>\n";
     echo "<option value='0'>============</option> \n" ;
     echo "</select></font>\n";
     
     echo "Sub-categories : <font id=suv-categories><select>\n";
     echo "<option value='0'>=== none ===</option> \n" ;
     echo "</select></font>\n";
?>

<script language=Javascript>
function Inint_AJAX() {
   try { return new ActiveXObject("Msxml2.XMLHTTP");  } catch(e) {} //IE
   try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {} //IE
   try { return new XMLHttpRequest();          } catch(e) {} //Native Javascript
   alert("XMLHttpRequest not supported");
   return null;
};

function dochange(src, val) {
     var req = Inint_AJAX();
     req.onreadystatechange = function () { 
          if (req.readyState==4) {
               if (req.status==200) {
                    document.getElementById(src).innerHTML=req.responseText; //retuen value
               } 
          }
     };
     req.open("GET", "categories.php?data="+src+"&val="+val); //make connection
     req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=iso-8859-1"); // set Header
     req.send(null); //send value
}

window.onLoad=dochange('subcategories', -1);         // value in first dropdown
</script>

 

Thanks

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.