Problemas com o script...???
Boa tarde,
Se alguém puder me ajudar eu agradeceria muito...
Abaixo segue o código...
<html>
<head>
<title>Auto Drop Down com PhP e MySQL</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<?
$conecta=mysql_connect("10.74.7.2", "root", "admin");
$seleciona_db=mysql_select_db("nre", $conecta);
?>
<script LANGUAGE="JavaScript">
team = new Array(
<?
$sql="select * from escola order by municipio";
$sql_result=mysql_query($sql, $conecta);
$num=mysql_numrows($sql_result);
while ($row=mysql_fetch_array($sql_result)){
$conta=$conta+1;
$cod_municipio=$row["municipio"];
echo "new Array(\n";
$sub_sql="select * from escola where escola.municipio='$cod_municipio'";
$sub_result=mysql_query($sub_sql, $conecta);
$num_sub=mysql_numrows($sub_result);
if ($num_sub>=1){
echo "new Array(\"Todas\", 0),\n";
while ($rowx=mysql_fetch_array($sub_result)){
$codigo_sub=$rowx["nome_escola"];
$sub_nome=$rowx["municipio"];
$conta_sub=$conta_sub+1;
if ($conta_sub==$num_sub){
echo "new Array(\"$sub_nome\", $codigo_sub)\n";
$conta_sub="";
}else{
echo "new Array(\"$sub_nome\", $codigo_sub),\n";
}
}
}else{
echo "new Array(\"Qualquer\", 0)\n";
}
if ($num>$conta){
echo "),\n";
}
}
echo ")\n";
echo ");\n";
?>
function fillSelectFromArray(selectCtrl, itemArray, goodPrompt, badPrompt, defaultItem) {
var i, j;
var prompt;
for (i = selectCtrl.options.length; i >= 0; i--) {
selectCtrl.options = null;
}
prompt = (itemArray != null) ? goodPrompt : badPrompt;
if (prompt == null) {
j = 0;
}
else {
selectCtrl.options[0] = new Option(prompt);
j = 1;
}
if (itemArray != null) {
for (i = 0; i < itemArray.length; i++) {
*selectCtrl.options[j] = new Option(itemArray**[0]);*
*if (itemArray**[1] != null) {*
*selectCtrl.options[j].value = itemArray**[1]; *
}
j++;
}
selectCtrl.options[0].selected = true;
}
}
*</script>*
*<center>*
*<form name="form1" method="post" action="">*
* <p>Aqui também temos itens a ser observados, verifique no codigo fonte</p>*
* <p><b><font face="Verdana, Arial, Helvetica, sans-serif" size="1">*
* <select name=categoria onChange="fillSelectFromArray(this.form.sub_categoria, ((this.selectedIndex == -1) ? null : team[this.selectedIndex-1]));">*
* <option>Escolha uma Categoria</option>*
<?
$sql="select distinct municipio from escola order by municipio";
$sql_result=mysql_query($sql, $conecta);
while ($row=mysql_fetch_array($sql_result)){
$cod_municipio=$row["municipio"];
$desc_municipio=$row["municipio"];
* ?>*
* <option value="<?echo $cod_municipio;?>"> *
* <?echo $desc_municipio;?>*
* </option>*
<?
}
* ?>*
* </select>*
* <select name="sub_categoria">*
* <option>---------------</option>*
* </select>*
* </font></b> </p>*
* </form></center>*
*</body>*
*</html>*Discussão (1)
Carregando comentários...