ramjai Posted February 4, 2009 Share Posted February 4, 2009 Hi all, I have three combo boxes, when i select a value in the first combo box, the second combo box should populate automatically and depending upon the second combo box the third should populate automatically. But i am getting the following error: lay[0] = "rawmaterial"; cat[0] = [ "IC"scat[0] = [ Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /opt/lampp/htdocs/combo.php on line 30 ]; , "MOSFET"scat[0] = [ Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /opt/lampp/htdocs/combo.php on line 30 ]; ]; lay[1] = "Semi finished Product"; cat[1] = []; Choose a layer Choose a category Choose a subcategory: can u rectify my error in the following code.............. <?php ?> <html> <head> <script language="JavaScript"> var lay = new Array(); var cat = new Array(); var scat = new Array();</script> <?php $con = mysql_connect("localhost","root","jairam") or die('Could not connect'); mysql_select_db("ERP"); $makes = mysql_query("SELECT * FROM layer"); $make_count = 0; while($make_row = mysql_fetch_array($makes, MYSQL_ASSOC)) { echo "lay[".$make_count."] = \"".$make_row["layername"]."\";\n"; $models = mysql_query("SELECT categoryname FROM category WHERE layerid=".$make_row["layerid"]); $model_count = 0; $num_models = mysql_num_rows($models); echo "cat[".$make_count."] = ["; while($model_row = mysql_fetch_array($models, MYSQL_ASSOC)) { echo " \"".$model_row["categoryname"]."\""; $bittis = mysql_query("SELECT subcategoryname FROM subcategory WHERE categoryid=".$model_row["categoryid"]); $bitti_count=0; echo "scat[".$bitti_count."] = ["; while($bitti_row = mysql_fetch_array($bittis, MYSQL_ASSOC)) { echo "\"".$bitti_row["subcategoryname"]."\""; $bitti_count++; } echo "];\n"; $model_count++; if($model_count < $num_models) echo ", "; } echo "];\n"; $make_count++; } mysql_close($con); ?> <script> function populateMakes() { var makeSel = document.getElementById("layername"); makeSel.length = 0; for(var i=0; i<lay.length; i++) { makeSel.options = new Option(lay, lay); } } function doChangeOptions() { var modelSel = document.getElementById("categoryname"); modelSel.length = 0; var sel = document.getElementById("layername").selectedIndex; alert(sel); var currArr = cat[sel]; alert(currArr); for(var i=0; i<currArr.length; i++) { modelSel.options = new Option(currArr, currArr); } } function doChangeOptions1() { var bittiSel = document.getElementById("subcategoryname"); bittiSel.length = 0; var sel = document.getElementById("categoryname").selectedIndex; alert(sel); var currArr = scat[sel]; alert(currArr); for(var i=0; i<currArr.length; i++) { bittiSel.options = new Option(currArr, currArr); } } </script> </head> <body onload="populateMakes();doChangeOptions();doChangeOptions1();"> <P>Choose a layer <select id="layername" onchange="doChangeOptions()"> </select> </p> <p>Choose a category <select id="categoryname" onchange="doChangeOptions1()"> </select> </p> <p>Choose a subcategory: <select id="subcategoryname"> </select> </p> </body> </html> Link to comment https://forums.phpfreaks.com/topic/143811-error-in-mysql_fetch_array/ Share on other sites More sharing options...
The Little Guy Posted February 4, 2009 Share Posted February 4, 2009 try this for each query: mysql_query("ENTER QUERY HERE")or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/143811-error-in-mysql_fetch_array/#findComment-754717 Share on other sites More sharing options...
ngreenwood6 Posted February 4, 2009 Share Posted February 4, 2009 Please use code tags. I think the problem is with your uses of single and double quotes. First of all I don't see any single quotes. Also you should be escaping double quotes inside of double quotes which it does not appear you are doing. For example this is incorrect: echo " hello "man", how are you"; You can either do this (which is dumb in this case but works better in other cases trust me): echo "hello 'man', how are you"; or you can do this: echo "hello \"man\", how are you"; Does that make sense? Link to comment https://forums.phpfreaks.com/topic/143811-error-in-mysql_fetch_array/#findComment-754719 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.