Muy buenas tardes vengo para que me ayuden encontre un codigo para hacer este escript que es el link siguiente http://www.tunait.com/tutoriales/listasdependientesphpmysql2parte.php, ya tengo mi codigo pero no llego haber lo que necesito no se que estare haciendo mal ayudenme la mano ya me frustre y estoy bloqueado gracias ... Mi codigo es:
<?php
session_start();
header( 'Content-Type: text/html;charset=iso-8859-1' );
//include ("../conectarse/validar.php");
//require("../conectarse/guardian.php");
include ("conectar.php");
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento sin título</title>
<script type="text/javascript">
function slctr(texto, valor){
this.texto = texto
this.valor=valor
}
function slctryole(cual,donde){
if(cual.selectedIndex != 0){
donde.length=0
cual = eval(cual.value)
for(m=0;m<cual.length;m++){
var nuevaOpcion = new Option(cual[m].texto);
donde.options[m] = nuevaOpcion;
if(cual[m].valor != null){
donde.options[m].value = cual[m].valor
}
else{
donde.options[m].value = cual[m].texto
}
}
}
}
<?
$query = mysql_query("select * from tbl_ingredientes ORDER BY id_tbl_ingredientes");
$ingre = array();
while($res = mysql_fetch_assoc($query)){
$contador = 0;
if($res["id_tbl_ingredientes_padre"] == 0) $ingre["cat_".$res["id_tbl_ingredientes"]] = $res["ingrediente"];
?>
var cat_<?=$res["id_tbl_ingredientes"] ?>=new Array()
cat_<?=$res["id_tbl_ingredientes"] ."[".$contador++?>]= new slctr('<?=$res["ingrediente"] ?>')
<?
if($res["id_tbl_ingredientes_padre"] == 0){
$query2 = mysql_query("select id_tbl_ingredientes, ingrediente as 'nombre' from tbl_ingredientes where id_tbl_ingredientes_padre = ". $res["id_tbl_ingredientes"]. " order by ingrediente");
}
else{
$query2 = mysql_query("select id_tbl_almacen,tbl_ingredientes_id_tbl_ingrediente s, lote as 'nombre' from tbl_almacen, tbl_ingredientes where tbl_ingredientes_id_tbl_ingredientes = ". $res["id_tbl_ingredientes"]. " order by id_tbl_almacen");
}
while($res2 = mysql_fetch_assoc($query2)){ ?>
cat_<?=$res["id_tbl_ingredientes"]."[".$contador++ ?>] = new slctr("<?=$res2["lote"]?>",'cat_<?=$res2["tbl_ingredientes_id_tbl_ingredientes"]?>')
<? }
}
?>
//-->
</script>
</head>
<body>
<form>
<fieldset>
<p>
<select name="select" onChange="slctryole(this,this.form.select2)">
<option>- - Seleccionar - -</option>
<?
foreach($ingre as $idd =>$cat){ ?>
<option value="<?=$idd?>">
<?=$cat?>
</option>
<?
}
?>
</select>
<select name="select2" onChange="slctryole(this,this.form.select3)">
<option>- - - - - -</option>
</select>
<select name="select3">
<option>- - - - - -</option>
</select>
</fieldset>
</form>
</body>
</html>
--------------BASE DE DATOS--------------------------------
CREATE TABLE tbl_marca (
id_tbl_marca INTEGER(4) UNSIGNED NOT NULL AUTO_INCREMENT,
marca VARCHAR(50) NULL,
PRIMARY KEY(id_tbl_marca)
);
CREATE TABLE tbl_fuente_financiamiento (
id_tbl_fuente_financiamiento INTEGER(2) UNSIGNED NOT NULL AUTO_INCREMENT,
financiamiento VARCHAR(20) NULL,
PRIMARY KEY(id_tbl_fuente_financiamiento)
);
CREATE TABLE tbl_provedor (
id_tbl_provedor INTEGER(4) UNSIGNED NOT NULL AUTO_INCREMENT,
provedor VARCHAR(50) NULL,
PRIMARY KEY(id_tbl_provedor)
);
CREATE TABLE tbl_ingredientes (
id_tbl_ingredientes INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
tbl_marca_id_tbl_marca INTEGER(4) UNSIGNED NOT NULL,
tbl_provedor_id_tbl_provedor INTEGER(4) UNSIGNED NOT NULL,
tbl_fuente_financiamiento_id_tbl_fuente_financiami ento INTEGER(2) UNSIGNED NOT NULL,
ingrediente VARCHAR(20) NULL,
id_tbl_ingredientes_padre INTEGER UNSIGNED NULL,
PRIMARY KEY(id_tbl_ingredientes),
INDEX tbl_ingredientes_FKIndex1(tbl_fuente_financiamient o_id_tbl_fuente_financiamiento),
INDEX tbl_ingredientes_FKIndex2(tbl_provedor_id_tbl_prov edor),
INDEX tbl_ingredientes_FKIndex3(tbl_marca_id_tbl_marca),
FOREIGN KEY(tbl_fuente_financiamiento_id_tbl_fuente_financ iamiento)
REFERENCES tbl_fuente_financiamiento(id_tbl_fuente_financiami ento)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
FOREIGN KEY(tbl_provedor_id_tbl_provedor)
REFERENCES tbl_provedor(id_tbl_provedor)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
FOREIGN KEY(tbl_marca_id_tbl_marca)
REFERENCES tbl_marca(id_tbl_marca)
ON DELETE NO ACTION
ON UPDATE NO ACTION
);
CREATE TABLE tbl_almacen (
id_tbl_almacen INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
tbl_ingredientes_id_tbl_ingredientes INTEGER UNSIGNED NOT NULL,
kilogramos INTEGER UNSIGNED NULL,
observaciones VARCHAR(50) NULL,
recibio VARCHAR(50) NULL,
fecha DATE NULL,
lote INTEGER UNSIGNED NULL,
PRIMARY KEY(id_tbl_almacen),
INDEX tbl_bodega_FKIndex1(tbl_ingredientes_id_tbl_ingred ientes),
FOREIGN KEY(tbl_ingredientes_id_tbl_ingredientes)
REFERENCES tbl_ingredientes(id_tbl_ingredientes)
ON DELETE NO ACTION
ON UPDATE NO ACTION
);
CREATE TABLE tbl_sld_almacen (
id_tbl_sld_almacen INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
tbl_almacen_id_tbl_almacen INTEGER UNSIGNED NOT NULL,
fecha DATE NULL,
kgsalida INTEGER UNSIGNED NULL,
kgactual INTEGER UNSIGNED NULL,
PRIMARY KEY(id_tbl_sld_almacen),
INDEX tbl_sal_almacen_FKIndex1(tbl_almacen_id_tbl_almace n),
FOREIGN KEY(tbl_almacen_id_tbl_almacen)
REFERENCES tbl_almacen(id_tbl_almacen)
ON DELETE NO ACTION
ON UPDATE NO ACTION
);