larsbrimmer Posted January 30, 2009 Share Posted January 30, 2009 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 Link to comment https://forums.phpfreaks.com/topic/143096-is-sql-correct-for-this-ajax-drop-down-menu/ Share on other sites More sharing options...
printf Posted January 30, 2009 Share Posted January 30, 2009 Other than using depreciated functions and both your control statements containing the same question (that doesn't make sense), I can tell what is wrong. How about you telling us what is wrong, and then maybe we can help you diagnose the error! Link to comment https://forums.phpfreaks.com/topic/143096-is-sql-correct-for-this-ajax-drop-down-menu/#findComment-750521 Share on other sites More sharing options...
larsbrimmer Posted January 30, 2009 Author Share Posted January 30, 2009 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 Link to comment https://forums.phpfreaks.com/topic/143096-is-sql-correct-for-this-ajax-drop-down-menu/#findComment-750528 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.