error in mysql_fetch_array()

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
kousalya
Forum Newbie
Posts: 4
Joined: Mon Feb 02, 2009 2:25 am

error in mysql_fetch_array()

Post by kousalya »

Hi all,
when i run the following code i am getting this error can any one help me out.........

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:


Codings

<?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>
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: error in mysql_fetch_array()

Post by JAB Creations »

Execute line 30 in MySQL and read the error message.

Use [syntax=php][/syntax], [syntax=php][/syntax], and [mysql][/mysql] BB code to make your posts readable.
Post Reply