Hey,
Been looking all over the net and all over these forums and I still cannot find an answer on how to do this double drop down list depending on the first item selected.
This is what I am using at the moment, found the majority of the code somewhere else where they thought they had it, but it's not working.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252" x-undefined>
<title>Test</title>
</head>
<body>
<?php
#db connection#
$SQLhost="localhost";
$SQLuser="oip";
$SQLpass="617dam";
$SQLdb="oipdb";
mysql_connect ($SQLhost, $SQLuser, $SQLpass);
mysql_select_db ($SQLdb);
$query = "SELECT category_id, category_name FROM FILES_CATEGORIES";
$result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());
$query2 = mysql_query("SELECT * FROM FILES_CATEGORIES_SUB LEFTJOIN FILES_CATEGORIES ON FILES_CATEGORIES.category_id = FILES_CATEGORIES_SUB.category_id");
$result2 = mysql_query($query2) or die ("Error in query: $query2. " . mysql_error());
echo "<br>";
$CategoryCount = 0
while($array = mysql_fetch_row($result))
{
$CurrentRow ++ ;
printf($array[0]);
$MoArrayIndex[$array[0]] = $CategoryCount ;
$StartMoArray[$CategoryCount] = 1 ;
echo "<br>";
}
}
while($array = mysql_fetch_row($result2))
{
IF StartMoArray[$MoArrayIndex[$array[1]]] = 1 {
PHPMoArray[$MoArrayIndex[$array[1]]] ='' ;
StartMoArray[$MoArrayIndex[$array[1]]] = 0
}
Else
PHPMoArray[$MoArrayIndex[$array[1]]] .= ',';
}
PHPMoArray[$MoArrayIndex[$array[1]]] .= '"'.$array[0].'"';
}
}
?>
<script type ="text/javascript">
var MoArray = new Array(2);
<?php
for ($i = 1; $i <= $CategoryCount; $i++) {
echo "MoArray[$i] = new Array($PHPMoArray[$i]);\n";
}
?>
function populate(index)
{
var x = index;
while (document.forms[0].model.options.length) // removes previous stuff from form!
{
document.forms[0].model.options.remove(0)
}
for (var i=0;i<MoArray[x].length;i++) // insert the data from array!
{
newOpt = document.createElement("OPTION");
newOpt.text = MoArray[index][i];
document.forms[0].model.options.add(newOpt)
}
}
</script>
<form name="test">
<select name="mo" style = "width:152px;font:200 11px arial;" onChange="populate(this.options[this.selectedIndex].value)">
<option value = 0> Select A </option>
<?php
while ($row = mysql_fetch_array($result2))
{
?>
<option value= <?php echo $row["category_id"]; ?> >
<?php echo $row["category_name"]; ?>
</option>
<?php
}
?>
</select>
<br><br><br><br>
<select name="model" size = 5 style = "width:152px;font:200 11px arial;">
<option value=0> Options WIll Appear Here </option>
</select>
</form>
<?php
mysql_close($link);
?>
</body>
</html>
I get a Parse Error on line 29 which is:
while($array = mysql_fetch_row($result))
Any ideas on how to get this working? Pulling my hair out on this one.
Cheers,
Chris