Foros del Web » Programando para Internet » Jquery »

Jquery - Combos Multiples

Estas en el tema de Jquery - Combos Multiples en el foro de Jquery en Foros del Web. Buenos Días, Tengo una consulta con JQuery, estoy creando una serie de combos multiples dependientes entre si. Al cambiar el valor de un combo lo ...
  #1 (permalink)  
Antiguo 27/05/2011, 10:34
Avatar de rfadgrmm  
Fecha de Ingreso: junio-2009
Mensajes: 74
Antigüedad: 17 años, 3 meses
Puntos: 1
Pregunta Jquery - Combos Multiples

Buenos Días,

Tengo una consulta con JQuery, estoy creando una serie de combos multiples dependientes entre si. Al cambiar el valor de un combo lo hace bien, pero sólo lo hace una vez, después no se vuelve a ejecutar, les dejo el código de mis archivos en php, espero se publique...

Archivo servicios.php

Código PHP:
<?php
    
//CLASES...
    
include_once("bin/class.grupos.php");
    include_once(
"bin/class.selector.servicios.php");
    
    
//MODULOS...
    
include_once("mods/cambio.servicios.php");
    
    
$cn = mysql_connect("localhost", "usuario", "clave");
    
mysql_select_db("mibasedatos", $cn);
    
    
//VALORES DE EJEMPLO... (VINCULADO A UNA BASE DE DATOS A FUTURO)
    
$propuestas = array(
        
"Cliente" => 12663,
        
"Pedido" => 1925,
        
"Propuesta" => 2155,
        
"Grupo" => 4421
    
);
    
$grupos = new Grupos;
    
$grupos->datos = $propuestas;
    
$propuestas["Principal"] = $grupos->Actividad($cn);
    unset(
$grupos);
    
$propuestas["Servicios"][133641] = array();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <script src="scripts/jquery-1.6.1.js" type="text/javascript"></script>
        <script type="text/javascript">
        <!--
            $(document).ready(function() {
                
                $("#lb_proveedor").change(function() {
                    $.post("mods/combos.cambio.servicios.php", { PSID:$("#lb_hd_propuesta_servicio").val(), principal:$("#lb_hd_principal").val(), caso:1, proveedor:$("#lb_proveedor").val() }, function(data) { $("#frm_servicios").html(data); })
                });
                
                $("#lb_ciudad").change(function() {
                    $.post("mods/combos.cambio.servicios.php", { PSID:$("#lb_hd_propuesta_servicio").val(), principal:$("#lb_hd_principal").val(), caso:2, proveedor:$("#lb_proveedor").val(), ciudad:$("#lb_ciudad").val() }, function(data) { $("#frm_servicios").html(data); })
                });
                
            });
        -->
        </script>
        <style type="text/css">
        <!--
            body {
                font-family: Verdana, Arial, sans-serif;
                font-size: 12px;
            }
            body, form, p {
                margin: 0px;
                padding: 0px;
            }
            p {
                padding-bottom: 4px;
            }
            .ComboBox {
                border: 1px solid #A4B97F;
                font-family: Verdana, Arial, Helvetica, sans-serif;
                font-size: 11px;
                color: #5C6D3D;
            }
        -->
        </style>
        <title>JQuery - Servicios</title>
    </head>
    <body>
<?php
    PROPUESTA_SERVICIOS_Multiples_Cambios
($cn, $propuestas);
?>
    </body>
</html>
<?php
    mysql_close
($cn);
?>
__________________
"Viajando en el espacio profundo, de nova en nova, y sorteando a veces uno que otro agujero negro..." Peru@D
  #2 (permalink)  
Antiguo 27/05/2011, 10:39
Avatar de rfadgrmm  
Fecha de Ingreso: junio-2009
Mensajes: 74
Antigüedad: 17 años, 3 meses
Puntos: 1
Pregunta Respuesta: Jquery - Combos Multiples

Continuación: archivo mods/cambio.servicios.php (Primera sección)

Código PHP:
<?php
    
function PROPUESTA_SERVICIOS_Multiples_Cambios($cn, $extras, $inicial = 0) {
        
$tab_index = 30;
        
$seleccion = array();
        
$ids = array_keys($extras["Servicios"]);
        foreach (
$ids as $id) {
            
$PSID = $id;
        }
        
$selectores = new SelectorProgramaServicios;
        
/**** LEYENDA INICIAL ****/
        
$bloques = array(
            
0 => "SELECT s.id AS id, s.descripcion AS servicio FROM servicios s INNER JOIN",
            
1 => "propuestaservicios ps ON (ps.servicio = s.id) WHERE ps.id = {$PSID}"
        
);
        
$sql = implode(" ", $bloques);
        
$rs = mysql_query($sql, $cn);
        
$encontrado = mysql_num_rows($rs);
        if (
$encontrado) {
            while (
$ma = mysql_fetch_array($rs)) {
                
$leyendas = array(
                    
"ID" => $ma["id"],
                    
"Servicio" => $ma["servicio"]
                );
            }
            
$ma = "";
        }
        
mysql_free_result($rs);
        
/**** FIN: LEYENDA INICIAL ****/
        
if (!$inicial) {
            
$selectores->origen = 1;
            
$selectores->datos = $extras;
            
$extras = $selectores->ServicioBase($cn);
            
$extras["Servicios"][$PSID]["Bases"] = array(
                
"Proveedor" => $extras["Servicios"][$PSID]["Proveedor"],
                
"Ciudad" => $extras["Servicios"][$PSID]["Ciudad"],
                
"TipoServicio" => $extras["Servicios"][$PSID]["TipoServicio"],
                
"CategoriaServicio" => $extras["Servicios"][$PSID]["CategoriaServicio"],
                
"Servicio" => $extras["Servicios"][$PSID]["Servicio"],
                
"Acomodacion" => $extras["Servicios"][$PSID]["Acomodacion"],
                
"ValorServicio" => $extras["Servicios"][$PSID]["ValorServicio"],
                
"Obligatorio" => $extras["Servicios"][$PSID]["Obligatorio"]
            );
        }
?>
        <form action="servicios.php" method="post">
            
            <div id="frm_servicios" style="clear: both; margin-left: 20px; padding-top: 20px; width: 48%;">
                
                <div style="clear: both; width: 100%;">
                    <div style="float: none; width: 100%;">
                        <p style="padding-bottom: 20px;"><?php echo "Cambiar Servicio Nº {$leyendas["ID"]} - {$leyendas["Servicio"]}"; ?></p>
                    </div>
                    <div style="clear: both; font-size: 1px; width: 100%;">&nbsp;</div>
                </div>
                <div style="clear: both; width: 100%;">
                    <div style="float: left; width: 30%;">
                        <div style="float: none; width: 100%;">
                            <p><label for="lb_proveedor">Proveedor / Operador :</label></p>
                        </div>
                    </div>
<?php
        
if ($extras["Principal"]) {
            
$limites = "AND s.tiposervicio NOT IN (2)";
        } else {
            
$limites = "";
        }
        
$bloques = array(
            
0 => "SELECT DISTINCT p.id AS id, p.nombrecomercial AS nombre",
            
1 => "FROM proveedores p INNER JOIN servicios s ON (s.proveedor = p.id)",
            
2 => "INNER JOIN tarifarios t ON (s.id = t.servicio) WHERE s.estado = 1 AND s.eliminado = 0",
            
3 => "{$limites}",
            
4 => "ORDER BY p.nombrecomercial"
        
);
        
$arreglo = array();
        
$sql = implode(" ", $bloques);
        
$rs = mysql_query($sql, $cn);
        
$encontrados = mysql_num_rows($rs);
        if (
$encontrados) {
            while (
$ma = mysql_fetch_array($rs)) {
                
$arreglo[$ma["id"]] = $ma["nombre"];
            }
            
$ma = "";
        }
        
mysql_free_result($rs);
        
//SERVICIO BASE... (UNA VEZ)
        
if (!$inicial) {
            
$sql = "SELECT p.id AS id, p.nombrecomercial AS nombre FROM proveedores p WHERE p.id = {$extras["Servicios"][$PSID]["Bases"]["Proveedor"]}";
            
$rs = mysql_query($sql, $cn);
            
$encontrados = mysql_num_rows($rs);
            if (
$encontrados) {
                while (
$ma = mysql_fetch_array($rs)) {
                    
$arreglo[$ma["id"]] = $ma["nombre"];
                }
                
$ma = "";
            }
            
mysql_free_result($rs);
        }
        
//FIN: SERVICIO BASE... (UNA VEZ)
?>
                    <div style="float: left; width: 70%;">
                        <div style="float: none; width: 100%;">
                            <p><select name="sel_proveedores" id="lb_proveedor" class="ComboBox" style="width: 320px;" tabindex="<?php echo $tab_index++; ?>">
<?php
        
if (count($arreglo)) {
            
$llaves = array_keys($arreglo);
            foreach (
$llaves as $llave) {
                if (
$llave == $extras["Servicios"][$PSID]["Proveedor"]) {
                    
$seleccion[0] = " selected=\"selected\"";
                } else {
                    
$seleccion[0] = "";
                }
?>
                                <option value="<?php echo $llave; ?>"<?php echo $seleccion[0]; ?>><?php echo $arreglo[$llave]; ?></option>
<?php
            
}
        } else {
?>
                                <option value="0">&nbsp;</option>
<?php
        
}
?>
                            </select></p>
                        </div>
                    </div>
                    <div style="clear: both; font-size: 1px; width: 100%;">&nbsp;</div>
                </div>
                <div style="clear: both; width: 100%;">
                    <div style="float: left; width: 30%;">
                        <div style="float: none; width: 100%;">
                            <p><label for="lb_ciudad">Ciudad / Destino :</label></p>
                        </div>
                    </div>
<?php
        
if ($extras["Principal"]) {
            
$limites = "AND s.tiposervicio NOT IN (2)";
        } else {
            
$limites = "";
        }
        
$bloques = array(
            
0 => "SELECT DISTINCT c.id AS id, c.nombre AS nombre",
            
1 => "FROM ciudades c INNER JOIN servicios s ON (s.ciudad = c.id)",
            
2 => "INNER JOIN tarifarios t ON (s.id = t.servicio) WHERE s.estado = 1",
            
3 => "AND s.eliminado = 0 AND s.proveedor = {$extras["Servicios"][$PSID]["Proveedor"]}",
            
4 => "{$limites}",
            
5 => "ORDER BY c.nombre"
        
);
        
$arreglo = array();
        
$sql = implode(" ", $bloques);
        
$rs = mysql_query($sql, $cn);
        
$encontrados = mysql_num_rows($rs);
        if (
$encontrados) {
            while (
$ma = mysql_fetch_array($rs)) {
                
$arreglo[$ma["id"]] = $ma["nombre"];
            }
            
$ma = "";
        }
        
mysql_free_result($rs);
        
//SERVICIO BASE... (UNA VEZ)
        
if (!$inicial) {
            
$sql = "SELECT c.id AS id, c.nombre AS nombre FROM ciudades c WHERE c.id = {$extras["Servicios"][$PSID]["Bases"]["Ciudad"]}";
            
$rs = mysql_query($sql, $cn);
            
$encontrados = mysql_num_rows($rs);
            if (
$encontrados) {
                while (
$ma = mysql_fetch_array($rs)) {
                    
$arreglo[$ma["id"]] = $ma["nombre"];
                }
                
$ma = "";
            }
            
mysql_free_result($rs);
        }
        
//FIN: SERVICIO BASE... (UNA VEZ)
?>
                    <div style="float: left; width: 70%;">
                        <div style="float: none; width: 100%;">
                            <p><select name="sel_ciudades" id="lb_ciudad" class="ComboBox" style="width: 320px;" tabindex="<?php echo $tab_index++; ?>">
<?php
        
if (count($arreglo)) {
            
$llaves = array_keys($arreglo);
            foreach (
$llaves as $llave) {
                if (
$llave == $extras["Servicios"][$PSID]["Ciudad"]) {
                    
$seleccion[1] = " selected=\"selected\"";
                } else {
                    
$seleccion[1] = "";
                }
?>
                                <option value="<?php echo $llave; ?>"<?php echo $seleccion[1]; ?>><?php echo $arreglo[$llave]; ?></option>
<?php
            
}
        } else {
?>
                                <option value="0">&nbsp;</option>
<?php
        
}
?>
                            </select></p>
                        </div>
                    </div>
                    <div style="clear: both; font-size: 1px; width: 100%;">&nbsp;</div>
                </div>
                <div style="clear: both; width: 100%;">
                    <div style="float: left; width: 30%;">
                        <div style="float: none; width: 100%;">
                            <p><label for="lb_tiposervicio">Tipo de Servicio :</label></p>
                        </div>
                    </div>
<?php
        
if ($extras["Principal"]) {
            
$limites = "AND ts.id NOT IN (2)";
        } else {
            
$limites = "";
        }
        
$bloques = array(
            
0 => "SELECT DISTINCT ts.id AS id, ts.nombre AS nombre",
            
1 => "FROM tiposservicio ts INNER JOIN servicios s ON (s.tiposervicio = ts.id)",
            
2 => "INNER JOIN tarifarios t ON (s.id = t.servicio) WHERE s.estado = 1 AND",
            
3 => "s.eliminado = 0 AND s.proveedor = {$extras["Servicios"][$PSID]["Proveedor"]} AND",
            
4 => "s.ciudad = {$extras["Servicios"][$PSID]["Ciudad"]}",
            
5 => "{$limites}",
            
6 => "ORDER BY ts.nombre"
        
);
        
$arreglo = array();
        
$sql = implode(" ", $bloques);
        
$rs = mysql_query($sql, $cn);
        
$encontrados = mysql_num_rows($rs);
        if (
$encontrados) {
            while (
$ma = mysql_fetch_array($rs)) {
                
$arreglo[$ma["id"]] = $ma["nombre"];
            }
            
$ma = "";
        }
        
mysql_free_result($rs);
        
//SERVICIO BASE... (UNA VEZ)
        
if (!$inicial) {
            
$sql = "SELECT ts.id AS id, ts.nombre AS nombre FROM tiposservicio ts WHERE ts.id = {$extras["Servicios"][$PSID]["Bases"]["TipoServicio"]}";
            
$rs = mysql_query($sql, $cn);
            
$encontrados = mysql_num_rows($rs);
            if (
$encontrados) {
                while (
$ma = mysql_fetch_array($rs)) {
                    
$arreglo[$ma["id"]] = $ma["nombre"];
                }
                
$ma = "";
            }
            
mysql_free_result($rs);
        }
        
//FIN: SERVICIO BASE... (UNA VEZ)
?>
                    <div style="float: left; width: 70%;">
                        <div style="float: none; width: 100%;">
                            <p><select name="sel_tiposservicio" id="lb_tiposervicio" class="ComboBox" style="width: 320px;" tabindex="<?php echo $tab_index++; ?>">
<?php
        
if (count($arreglo)) {
            
$llaves = array_keys($arreglo);
            foreach (
$llaves as $llave) {
                if (
$llave == $extras["Servicios"][$PSID]["TipoServicio"]) {
                    
$seleccion[2] = " selected=\"selected\"";
                } else {
                    
$seleccion[2] = "";
                }
?>
                                <option value="<?php echo $llave; ?>"<?php echo $seleccion[2]; ?>><?php echo $arreglo[$llave]; ?></option>
<?php
            
}
        } else {
?>
                                <option value="0">&nbsp;</option>
<?php
        
}
?>
                            </select></p>
                        </div>
                    </div>
                    <div style="clear: both; font-size: 1px; width: 100%;">&nbsp;</div>
                </div>
__________________
"Viajando en el espacio profundo, de nova en nova, y sorteando a veces uno que otro agujero negro..." Peru@D
  #3 (permalink)  
Antiguo 27/05/2011, 10:42
Avatar de rfadgrmm  
Fecha de Ingreso: junio-2009
Mensajes: 74
Antigüedad: 17 años, 3 meses
Puntos: 1
Pregunta Respuesta: Jquery - Combos Multiples

Continuación: archivo mods/cambio.servicios.php (Segunda sección)

Código PHP:
                <div style="clear: both; width: 100%;">
                    <div style="float: left; width: 30%;">
                        <div style="float: none; width: 100%;">
                            <p><label for="lb_categoriaservicio">Categoria del Servicio :</label></p>
                        </div>
                    </div>
<?php
        $bloques 
= array(
            
0 => "SELECT DISTINCT cs.id AS id, cs.nombre AS nombre FROM categoriasservicio cs",
            
1 => "INNER JOIN servicios s ON (s.categoriaservicio = cs.id) INNER JOIN tarifarios t ON (s.id = t.servicio)",
            
2 => "WHERE s.estado = 1 AND s.eliminado = 0 AND s.proveedor = {$extras["Servicios"][$PSID]["Proveedor"]}",
            
3 => "AND s.ciudad = {$extras["Servicios"][$PSID]["Ciudad"]} AND s.tiposervicio = {$extras["Servicios"][$PSID]["TipoServicio"]}",
            
4 => "ORDER BY cs.nombre"
        
);
        
$arreglo = array();
        
$sql = implode(" ", $bloques);
        
$rs = mysql_query($sql, $cn);
        
$encontrados = mysql_num_rows($rs);
        if (
$encontrados) {
            while (
$ma = mysql_fetch_array($rs)) {
                
$arreglo[$ma["id"]] = $ma["nombre"];
            }
            
$ma = "";
        }
        
mysql_free_result($rs);
        
//SERVICIO BASE... (UNA VEZ)
        
if (!$inicial) {
            
$sql = "SELECT cs.id AS id, cs.nombre AS nombre FROM categoriasservicio cs WHERE cs.id = {$extras["Servicios"][$PSID]["Bases"]["CategoriaServicio"]}";
            
$rs = mysql_query($sql, $cn);
            
$encontrados = mysql_num_rows($rs);
            if (
$encontrados) {
                while (
$ma = mysql_fetch_array($rs)) {
                    
$arreglo[$ma["id"]] = $ma["nombre"];
                }
                
$ma = "";
            }
            
mysql_free_result($rs);
        }
        
//FIN: SERVICIO BASE... (UNA VEZ)
?>
                    <div style="float: left; width: 70%;">
                        <div style="float: none; width: 100%;">
                            <p><select name="sel_categoriasservicio" id="lb_categoriaservicio" class="ComboBox" style="width: 320px;" tabindex="<?php echo $tab_index++; ?>">
<?php
        
if (count($arreglo)) {
            
$llaves = array_keys($arreglo);
            foreach (
$llaves as $llave) {
                if (
$llave == $extras["Servicios"][$PSID]["CategoriaServicio"]) {
                    
$seleccion[3] = " selected=\"selected\"";
                } else {
                    
$seleccion[3] = "";
                }
?>
                                <option value="<?php echo $llave; ?>"<?php echo $seleccion[3]; ?>><?php echo $arreglo[$llave]; ?></option>
<?php
            
}
        } else {
?>
                                <option value="0">&nbsp;</option>
<?php
        
}
?>
                            </select></p>
                        </div>
                    </div>
                    <div style="clear: both; font-size: 1px; width: 100%;">&nbsp;</div>
                </div>
                <div style="clear: both; width: 100%;">
                    <div style="float: left; width: 30%;">
                        <div style="float: none; width: 100%;">
                            <p><label for="lb_servicio">Nombre del Servicio :</label></p>
                        </div>
                    </div>
<?php
        $bloques 
= array(
            
0 => "SELECT DISTINCT s.id AS id, s.descripcion AS nombre, s.valorservicio AS valorservicio,",
            
1 => "s.precioobligatorio AS obligatorio FROM servicios s INNER JOIN tarifarios t ON (s.id = t.servicio)",
            
2 => "WHERE s.estado = 1 AND s.eliminado = 0 AND s.proveedor = {$extras["Servicios"][$PSID]["Proveedor"]}",
            
3 => "AND s.ciudad = {$extras["Servicios"][$PSID]["Ciudad"]}",
            
4 => "AND s.tiposervicio = {$extras["Servicios"][$PSID]["TipoServicio"]}",
            
5 => "AND s.categoriaservicio = {$extras["Servicios"][$PSID]["CategoriaServicio"]}",
            
6 => "ORDER BY s.descripcion"
        
);
        
$arreglo = array();
        
$sql = implode(" ", $bloques);
        
$rs = mysql_query($sql, $cn);
        
$encontrados = mysql_num_rows($rs);
        if (
$encontrados) {
            while (
$ma = mysql_fetch_array($rs)) {
                
$arreglo[$ma["id"]] = array(
                    
"Servicio" => $ma["nombre"],
                    
"Valor" => $ma["valorservicio"],
                    
"Obligatorio" => $ma["obligatorio"]
                );
            }
            
$ma = "";
        }
        
mysql_free_result($rs);
        
//SERVICIO BASE... (UNA VEZ)
        
if (!$inicial) {
            
$bloques = array(
                
0 => "SELECT s.id AS id, s.descripcion AS nombre, s.valorservicio AS valorservicio, s.precioobligatorio AS obligatorio",
                
1 => "FROM servicios s WHERE s.id = {$extras["Servicios"][$PSID]["Bases"]["Servicio"]}"
            
);
            
$sql = implode(" ", $bloques);
            
$rs = mysql_query($sql, $cn);
            
$encontrados = mysql_num_rows($rs);
            if (
$encontrados) {
                while (
$ma = mysql_fetch_array($rs)) {
                    
$arreglo[$ma["id"]] = array(
                        
"Servicio" => $ma["nombre"],
                        
"Valor" => $ma["valorservicio"],
                        
"Obligatorio" => $ma["obligatorio"]
                    );
                }
                
$ma = "";
            }
            
mysql_free_result($rs);
        }
        
//FIN: SERVICIO BASE... (UNA VEZ)
?>
                    <div style="float: left; width: 70%;">
                        <div style="float: none; width: 100%;">
                            <p><select name="sel_servicios" id="lb_servicio" class="ComboBox" style="width: 320px;" tabindex="<?php echo $tab_index++; ?>">
<?php
        
if (count($arreglo)) {
            
$llaves = array_keys($arreglo);
            foreach (
$llaves as $llave) {
                if (
$llave == $extras["Servicios"][$PSID]["Servicio"]) {
                    
$extras["Servicios"][$PSID]["ValorServicio"] = $arreglo[$llave]["Valor"];
                    
$extras["Servicios"][$PSID]["Obligatorio"] = $arreglo[$llave]["Obligatorio"];
                    
$seleccion[4] = " selected=\"selected\"";
                } else {
                    
$seleccion[4] = "";
                }
?>
                                <option value="<?php echo $llave; ?>" title="<?php echo $arreglo[$llave]["Servicio"]; ?>"<?php echo $seleccion[4]; ?>><?php echo $arreglo[$llave]["Servicio"]; ?></option>
<?php
            
}
        } else {
?>
                                <option value="0">&nbsp;</option>
<?php
        
}
?>
                            </select></p>
                        </div>
                    </div>
                    <div style="clear: both; font-size: 1px; width: 100%;">&nbsp;</div>
                </div>
                <div style="clear: both; width: 100%;">
                    <div style="float: left; width: 30%;">
                        <div style="float: none; width: 100%;">
                            <p><label for="lb_acomodacion"><abbr lang="es" title="Habitación">Habit.</abbr> / Acomodación :</label></p>
                        </div>
                    </div>
<?php
        $bloques 
= array(
            
0 => "SELECT DISTINCT ac.id AS id, ac.nombre AS nombre FROM acomodaciones ac INNER JOIN tarifarios t",
            
1 => "ON (t.acomodacion = ac.id) INNER JOIN servicios s ON (t.servicio = s.id) WHERE s.estado = 1 AND s.eliminado = 0",
            
2 => "AND s.proveedor = {$extras["Servicios"][$PSID]["Proveedor"]} AND s.ciudad = {$extras["Servicios"][$PSID]["Ciudad"]}",
            
3 => "AND s.tiposervicio = {$extras["Servicios"][$PSID]["TipoServicio"]} AND s.categoriaservicio = {$extras["Servicios"][$PSID]["CategoriaServicio"]}",
            
4 => "AND s.id = {$extras["Servicios"][$PSID]["Servicio"]} ORDER BY ac.nombre"
        
);
        
$arreglo = array();
        
$sql = implode(" ", $bloques);
        
$rs = mysql_query($sql, $cn);
        
$encontrados = mysql_num_rows($rs);
        if (
$encontrados) {
            while (
$ma = mysql_fetch_array($rs)) {
                
$arreglo[$ma["id"]] = $ma["nombre"];
            }
            
$ma = "";
        }
        
mysql_free_result($rs);
        
//SERVICIO BASE... (UNA VEZ)
        
if (!$inicial) {
            
$sql = "SELECT ac.id AS id, ac.nombre AS nombre FROM acomodaciones ac WHERE ac.id = {$extras["Servicios"][$PSID]["Bases"]["Acomodacion"]}";
            
$rs = mysql_query($sql, $cn);
            
$encontrados = mysql_num_rows($rs);
            if (
$encontrados) {
                while (
$ma = mysql_fetch_array($rs)) {
                    
$arreglo[$ma["id"]] = $ma["nombre"];
                }
                
$ma = "";
            }
            
mysql_free_result($rs);
        }
        
//FIN: SERVICIO BASE... (UNA VEZ)
?>
                    <div style="float: left; width: 70%;">
                        <div style="float: none; width: 100%;">
                            <p><select name="sel_acomodaciones" id="lb_acomodacion" class="ComboBox" style="width: 320px;" tabindex="<?php echo $tab_index++; ?>">
<?php
        
if (count($arreglo)) {
            
$llaves = array_keys($arreglo);
            foreach (
$llaves as $llave) {
                if (
$llave == $extras["Servicios"][$PSID]["Acomodacion"]) {
                    
$seleccion[5] = " selected=\"selected\"";
                } else {
                    
$seleccion[5] = "";
                }
                if (
$arreglo[$llave] == "[Variable]") {
                    
$acomodacion = "&nbsp;";
                } else{
                    
$acomodacion = "{$arreglo[$llave]}";
                }
?>
                                <option value="<?php echo $llave; ?>"<?php echo $seleccion[5]; ?>><?php echo $acomodacion; ?></option>
<?php
            
}
        } else {
?>
                                <option value="0">&nbsp;</option>
<?php
        
}
?>
                            </select></p>
                        </div>
                    </div>
                    <div style="clear: both; font-size: 1px; width: 100%;">&nbsp;</div>
                </div>
                <div style="clear: both; font-size: 1px; width: 100%;">&nbsp;</div>
                
            </div>
__________________
"Viajando en el espacio profundo, de nova en nova, y sorteando a veces uno que otro agujero negro..." Peru@D
  #4 (permalink)  
Antiguo 27/05/2011, 10:43
Avatar de rfadgrmm  
Fecha de Ingreso: junio-2009
Mensajes: 74
Antigüedad: 17 años, 3 meses
Puntos: 1
Pregunta Respuesta: Jquery - Combos Multiples

Continuación: archivo mods/cambio.servicios.php (Tercera sección)

Código PHP:
            <input type="hidden" name="hd_base_proveedor" value="<?php echo $extras["Servicios"][$PSID]["Bases"]["Proveedor"]; ?>" />
            <input type="hidden" name="hd_base_ciudad" value="<?php echo $extras["Servicios"][$PSID]["Bases"]["Ciudad"]; ?>" />
            <input type="hidden" name="hd_base_tipo_servicio" value="<?php echo $extras["Servicios"][$PSID]["Bases"]["TipoServicio"]; ?>" />
            <input type="hidden" name="hd_base_categoria_servicio" value="<?php echo $extras["Servicios"][$PSID]["Bases"]["CategoriaServicio"]; ?>" />
            <input type="hidden" name="hd_base_servicio" value="<?php echo $extras["Servicios"][$PSID]["Bases"]["Servicio"]; ?>" />
            <input type="hidden" name="hd_base_acomodacion" value="<?php echo $extras["Servicios"][$PSID]["Bases"]["Acomodacion"]; ?>" />
            <input type="hidden" name="hd_base_valor_servicio" value="<?php echo $extras["Servicios"][$PSID]["Bases"]["ValorServicio"]; ?>" />
            <input type="hidden" name="hd_base_obligatorio" value="<?php echo $extras["Servicios"][$PSID]["Bases"]["Obligatorio"]; ?>" />
            
            <input type="hidden" name="hd_valor_servicio[<?php echo $PSID; ?>]" value="<?php echo $extras["Servicios"][$PSID]["ValorServicio"]; ?>" />
            
            <input type="hidden" name="hd_propuesta_servicio[<?php echo $PSID; ?>]" value="1" />
            
            <input type="hidden" name="hd_cliente" value="<?php echo $extras["Cliente"]; ?>" />
            <input type="hidden" name="hd_pedido" value="<?php echo $extras["Pedido"]; ?>" />
            <input type="hidden" name="hd_propuesta" value="<?php echo $extras["Propuesta"]; ?>" />
            <input type="hidden" name="hd_propuesta_grupo" value="<?php echo $extras["Grupo"]; ?>" />
            
            <input type="hidden" name="jq_propuesta_servicio" id="lb_hd_propuesta_servicio" value="<?php echo $PSID; ?>" />
            <input type="hidden" name="jq_grupo_principal" id="lb_hd_principal" value="<?php echo $extras["Principal"]; ?>" />
            
        </form>
<?php
        
unset($selectores);
    }
?>
__________________
"Viajando en el espacio profundo, de nova en nova, y sorteando a veces uno que otro agujero negro..." Peru@D
  #5 (permalink)  
Antiguo 27/05/2011, 10:46
Avatar de rfadgrmm  
Fecha de Ingreso: junio-2009
Mensajes: 74
Antigüedad: 17 años, 3 meses
Puntos: 1
Pregunta Respuesta: Jquery - Combos Multiples

Continuación: archivo mods/combos.cambio.servicios.php (Primera sección)
Este archivo lo estoy manejando por JQuery en servicios.php

Código PHP:
<?php
    
include_once("../bin/class.selector.servicios.php");
    
    
$cn = mysql_connect("localhost", "usuario", "clave");
    
mysql_select_db("mibasedatos", $cn);
    
    
$datos = array(
        
"PSID" => $_POST["PSID"],
        
"Principal" => $_POST["principal"],
        
"Caso" => $_POST["caso"]
    );
    switch (
$datos["Caso"]) {
        case 
1:
            
//PROVEEDOR...
            
$datos["Servicios"][$datos["PSID"]] = array(
                
"Proveedor" => $_POST["proveedor"]
            );
            break;
        case 
2:
            
//CIUDAD...
            
$datos["Servicios"][$datos["PSID"]] = array(
                
"Proveedor" => $_POST["proveedor"],
                
"Ciudad" => $_POST["ciudad"]
            );
            break;
        case 
3:
            
//TIPO DE SERVICIO...
            
$datos["Servicios"][$datos["PSID"]] = array(
                
"Proveedor" => $_POST["proveedor"],
                
"Ciudad" => $_POST["ciudad"],
                
"TipoServicio" => $_POST["tiposervicio"]
            );
            break;
        case 
4:
            
//CATEGORIA DE SERVICIO...
            
$datos["Servicios"][$datos["PSID"]] = array(
                
"Proveedor" => $_POST["proveedor"],
                
"Ciudad" => $_POST["ciudad"],
                
"TipoServicio" => $_POST["tiposervicio"],
                
"CategoriaServicio" => $_POST["categoriaservicio"]
            );
            break;
        case 
5:
            
//SERVICIO...
            
$datos["Servicios"][$datos["PSID"]] = array(
                
"Proveedor" => $_POST["proveedor"],
                
"Ciudad" => $_POST["ciudad"],
                
"TipoServicio" => $_POST["tiposervicio"],
                
"CategoriaServicio" => $_POST["categoriaservicio"],
                
"Servicio" => $_POST["servicio"]
            );
            break;
        default:
            
//NADA...
            
break;
    }
    
    
$tab_index = 30;
    
$seleccion = array();
    
    
/**** LEYENDA INICIAL ****/
    
$bloques = array(
        
0 => "SELECT s.id AS id, s.descripcion AS servicio FROM servicios s INNER JOIN",
        
1 => "propuestaservicios ps ON (ps.servicio = s.id) WHERE ps.id = {$datos["PSID"]}"
    
);
    
$sql = implode(" ", $bloques);
    
$rs = mysql_query($sql, $cn);
    
$encontrado = mysql_num_rows($rs);
    if (
$encontrado) {
        while (
$ma = mysql_fetch_array($rs)) {
            
$leyendas = array(
                
"ID" => $ma["id"],
                
"Servicio" => $ma["servicio"]
            );
        }
        
$ma = "";
    }
    
mysql_free_result($rs);
    
/**** FIN: LEYENDA INICIAL ****/
    
    
$selectores = new SelectorProgramaServicios;
    
$selectores->seleccion = $datos["Caso"];
    
$selectores->origen = $datos["Principal"];
    
$selectores->datos = $datos;
    
$datos = $selectores->Selecciones($cn);
    unset(
$selectores);
?>
                
                <div style="clear: both; width: 100%;">
                    <div style="float: none; width: 100%;">
                        <p style="padding-bottom: 20px;"><?php echo "Cambiar Servicio Nº {$leyendas["ID"]} - {$leyendas["Servicio"]}"; ?></p>
                    </div>
                    <div style="clear: both; font-size: 1px; width: 100%;">&nbsp;</div>
                </div>
                <div style="clear: both; width: 100%;">
                    <div style="float: left; width: 30%;">
                        <div style="float: none; width: 100%;">
                            <p><label for="lb_proveedor">Proveedor / Operador :</label></p>
                        </div>
                    </div>
<?php
        
if ($datos["Principal"]) {
            
$limites = "AND s.tiposervicio NOT IN (2)";
        } else {
            
$limites = "";
        }
        
$bloques = array(
            
0 => "SELECT DISTINCT p.id AS id, p.nombrecomercial AS nombre",
            
1 => "FROM proveedores p INNER JOIN servicios s ON (s.proveedor = p.id)",
            
2 => "INNER JOIN tarifarios t ON (s.id = t.servicio) WHERE s.estado = 1 AND s.eliminado = 0",
            
3 => "{$limites}",
            
4 => "ORDER BY p.nombrecomercial"
        
);
        
$arreglo = array();
        
$sql = implode(" ", $bloques);
        
$rs = mysql_query($sql, $cn);
        
$encontrados = mysql_num_rows($rs);
        if (
$encontrados) {
            while (
$ma = mysql_fetch_array($rs)) {
                
$arreglo[$ma["id"]] = $ma["nombre"];
            }
            
$ma = "";
        }
        
mysql_free_result($rs);
?>
                    <div style="float: left; width: 70%;">
                        <div style="float: none; width: 100%;">
                            <p><select name="sel_proveedores" id="lb_proveedor" class="ComboBox" style="width: 320px;" tabindex="<?php echo $tab_index++; ?>">
<?php
        
if (count($arreglo)) {
            
$llaves = array_keys($arreglo);
            foreach (
$llaves as $llave) {
                if (
$llave == $datos["Servicios"][$datos["PSID"]]["Proveedor"]) {
                    
$seleccion[0] = " selected=\"selected\"";
                } else {
                    
$seleccion[0] = "";
                }
?>
                                <option value="<?php echo $llave; ?>"<?php echo $seleccion[0]; ?>><?php echo $arreglo[$llave]; ?></option>
<?php
            
}
        } else {
?>
                                <option value="0">&nbsp;</option>
<?php
        
}
?>
                            </select></p>
                        </div>
                    </div>
                    <div style="clear: both; font-size: 1px; width: 100%;">&nbsp;</div>
                </div>
                <div style="clear: both; width: 100%;">
                    <div style="float: left; width: 30%;">
                        <div style="float: none; width: 100%;">
                            <p><label for="lb_ciudad">Ciudad / Destino :</label></p>
                        </div>
                    </div>
<?php
        
if ($datos["Principal"]) {
            
$limites = "AND s.tiposervicio NOT IN (2)";
        } else {
            
$limites = "";
        }
        
$bloques = array(
            
0 => "SELECT DISTINCT c.id AS id, c.nombre AS nombre",
            
1 => "FROM ciudades c INNER JOIN servicios s ON (s.ciudad = c.id)",
            
2 => "INNER JOIN tarifarios t ON (s.id = t.servicio) WHERE s.estado = 1",
            
3 => "AND s.eliminado = 0 AND s.proveedor = {$datos["Servicios"][$datos["PSID"]]["Proveedor"]}",
            
4 => "{$limites}",
            
5 => "ORDER BY c.nombre"
        
);
        
$arreglo = array();
        
$sql = implode(" ", $bloques);
        
$rs = mysql_query($sql, $cn);
        
$encontrados = mysql_num_rows($rs);
        if (
$encontrados) {
            while (
$ma = mysql_fetch_array($rs)) {
                
$arreglo[$ma["id"]] = $ma["nombre"];
            }
            
$ma = "";
        }
        
mysql_free_result($rs);
?>
                    <div style="float: left; width: 70%;">
                        <div style="float: none; width: 100%;">
                            <p><select name="sel_ciudades" id="lb_ciudad" class="ComboBox" style="width: 320px;" tabindex="<?php echo $tab_index++; ?>">
<?php
        
if (count($arreglo)) {
            
$llaves = array_keys($arreglo);
            foreach (
$llaves as $llave) {
                if (
$llave == $datos["Servicios"][$datos["PSID"]]["Ciudad"]) {
                    
$seleccion[1] = " selected=\"selected\"";
                } else {
                    
$seleccion[1] = "";
                }
?>
                                <option value="<?php echo $llave; ?>"<?php echo $seleccion[1]; ?>><?php echo $arreglo[$llave]; ?></option>
<?php
            
}
        } else {
?>
                                <option value="0">&nbsp;</option>
<?php
        
}
?>
                            </select></p>
                        </div>
                    </div>
                    <div style="clear: both; font-size: 1px; width: 100%;">&nbsp;</div>
                </div>
                <div style="clear: both; width: 100%;">
                    <div style="float: left; width: 30%;">
                        <div style="float: none; width: 100%;">
                            <p><label for="lb_tiposervicio">Tipo de Servicio :</label></p>
                        </div>
                    </div>
<?php
        
if ($datos["Principal"]) {
            
$limites = "AND ts.id NOT IN (2)";
        } else {
            
$limites = "";
        }
        
$bloques = array(
            
0 => "SELECT DISTINCT ts.id AS id, ts.nombre AS nombre",
            
1 => "FROM tiposservicio ts INNER JOIN servicios s ON (s.tiposervicio = ts.id)",
            
2 => "INNER JOIN tarifarios t ON (s.id = t.servicio) WHERE s.estado = 1 AND",
            
3 => "s.eliminado = 0 AND s.proveedor = {$datos["Servicios"][$datos["PSID"]]["Proveedor"]} AND",
            
4 => "s.ciudad = {$datos["Servicios"][$datos["PSID"]]["Ciudad"]}",
            
5 => "{$limites}",
            
6 => "ORDER BY ts.nombre"
        
);
        
$arreglo = array();
        
$sql = implode(" ", $bloques);
        
$rs = mysql_query($sql, $cn);
        
$encontrados = mysql_num_rows($rs);
        if (
$encontrados) {
            while (
$ma = mysql_fetch_array($rs)) {
                
$arreglo[$ma["id"]] = $ma["nombre"];
            }
            
$ma = "";
        }
        
mysql_free_result($rs);
?>
                    <div style="float: left; width: 70%;">
                        <div style="float: none; width: 100%;">
                            <p><select name="sel_tiposservicio" id="lb_tiposervicio" class="ComboBox" style="width: 320px;" tabindex="<?php echo $tab_index++; ?>">
<?php
        
if (count($arreglo)) {
            
$llaves = array_keys($arreglo);
            foreach (
$llaves as $llave) {
                if (
$llave == $datos["Servicios"][$datos["PSID"]]["TipoServicio"]) {
                    
$seleccion[2] = " selected=\"selected\"";
                } else {
                    
$seleccion[2] = "";
                }
?>
                                <option value="<?php echo $llave; ?>"<?php echo $seleccion[2]; ?>><?php echo $arreglo[$llave]; ?></option>
<?php
            
}
        } else {
?>
                                <option value="0">&nbsp;</option>
<?php
        
}
?>
                            </select></p>
                        </div>
                    </div>
                    <div style="clear: both; font-size: 1px; width: 100%;">&nbsp;</div>
                </div>
__________________
"Viajando en el espacio profundo, de nova en nova, y sorteando a veces uno que otro agujero negro..." Peru@D
  #6 (permalink)  
Antiguo 27/05/2011, 10:47
Avatar de rfadgrmm  
Fecha de Ingreso: junio-2009
Mensajes: 74
Antigüedad: 17 años, 3 meses
Puntos: 1
Pregunta Respuesta: Jquery - Combos Multiples

Continuación: archivo mods/combos.cambio.servicios.php (Segunda sección)
Este archivo lo estoy manejando por JQuery en servicios.php

Código PHP:
                <div style="clear: both; width: 100%;">
                    <div style="float: left; width: 30%;">
                        <div style="float: none; width: 100%;">
                            <p><label for="lb_categoriaservicio">Categoria del Servicio :</label></p>
                        </div>
                    </div>
<?php
        $bloques 
= array(
            
0 => "SELECT DISTINCT cs.id AS id, cs.nombre AS nombre FROM categoriasservicio cs",
            
1 => "INNER JOIN servicios s ON (s.categoriaservicio = cs.id) INNER JOIN tarifarios t ON (s.id = t.servicio)",
            
2 => "WHERE s.estado = 1 AND s.eliminado = 0 AND s.proveedor = {$datos["Servicios"][$datos["PSID"]]["Proveedor"]}",
            
3 => "AND s.ciudad = {$datos["Servicios"][$datos["PSID"]]["Ciudad"]} AND s.tiposervicio = {$datos["Servicios"][$datos["PSID"]]["TipoServicio"]}",
            
4 => "ORDER BY cs.nombre"
        
);
        
$arreglo = array();
        
$sql = implode(" ", $bloques);
        
$rs = mysql_query($sql, $cn);
        
$encontrados = mysql_num_rows($rs);
        if (
$encontrados) {
            while (
$ma = mysql_fetch_array($rs)) {
                
$arreglo[$ma["id"]] = $ma["nombre"];
            }
            
$ma = "";
        }
        
mysql_free_result($rs);
?>
                    <div style="float: left; width: 70%;">
                        <div style="float: none; width: 100%;">
                            <p><select name="sel_categoriasservicio" id="lb_categoriaservicio" class="ComboBox" style="width: 320px;" tabindex="<?php echo $tab_index++; ?>">
<?php
        
if (count($arreglo)) {
            
$llaves = array_keys($arreglo);
            foreach (
$llaves as $llave) {
                if (
$llave == $datos["Servicios"][$datos["PSID"]]["CategoriaServicio"]) {
                    
$seleccion[3] = " selected=\"selected\"";
                } else {
                    
$seleccion[3] = "";
                }
?>
                                <option value="<?php echo $llave; ?>"<?php echo $seleccion[3]; ?>><?php echo $arreglo[$llave]; ?></option>
<?php
            
}
        } else {
?>
                                <option value="0">&nbsp;</option>
<?php
        
}
?>
                            </select></p>
                        </div>
                    </div>
                    <div style="clear: both; font-size: 1px; width: 100%;">&nbsp;</div>
                </div>
                <div style="clear: both; width: 100%;">
                    <div style="float: left; width: 30%;">
                        <div style="float: none; width: 100%;">
                            <p><label for="lb_servicio">Nombre del Servicio :</label></p>
                        </div>
                    </div>
<?php
        $bloques 
= array(
            
0 => "SELECT DISTINCT s.id AS id, s.descripcion AS nombre, s.valorservicio AS valorservicio,",
            
1 => "s.precioobligatorio AS obligatorio FROM servicios s INNER JOIN tarifarios t ON (s.id = t.servicio)",
            
2 => "WHERE s.estado = 1 AND s.eliminado = 0 AND s.proveedor = {$datos["Servicios"][$datos["PSID"]]["Proveedor"]}",
            
3 => "AND s.ciudad = {$datos["Servicios"][$datos["PSID"]]["Ciudad"]}",
            
4 => "AND s.tiposervicio = {$datos["Servicios"][$datos["PSID"]]["TipoServicio"]}",
            
5 => "AND s.categoriaservicio = {$datos["Servicios"][$datos["PSID"]]["CategoriaServicio"]}",
            
6 => "ORDER BY s.descripcion"
        
);
        
$arreglo = array();
        
$sql = implode(" ", $bloques);
        
$rs = mysql_query($sql, $cn);
        
$encontrados = mysql_num_rows($rs);
        if (
$encontrados) {
            while (
$ma = mysql_fetch_array($rs)) {
                
$arreglo[$ma["id"]] = array(
                    
"Servicio" => $ma["nombre"],
                    
"Valor" => $ma["valorservicio"],
                    
"Obligatorio" => $ma["obligatorio"]
                );
            }
            
$ma = "";
        }
        
mysql_free_result($rs);
?>
                    <div style="float: left; width: 70%;">
                        <div style="float: none; width: 100%;">
                            <p><select name="sel_servicios" id="lb_servicio" class="ComboBox" style="width: 320px;" tabindex="<?php echo $tab_index++; ?>">
<?php
        
if (count($arreglo)) {
            
$llaves = array_keys($arreglo);
            foreach (
$llaves as $llave) {
                if (
$llave == $datos["Servicios"][$datos["PSID"]]["Servicio"]) {
                    
$datos["Servicios"][$datos["PSID"]]["ValorServicio"] = $arreglo[$llave]["Valor"];
                    
$datos["Servicios"][$datos["PSID"]]["Obligatorio"] = $arreglo[$llave]["Obligatorio"];
                    
$seleccion[4] = " selected=\"selected\"";
                } else {
                    
$seleccion[4] = "";
                }
?>
                                <option value="<?php echo $llave; ?>" title="<?php echo $arreglo[$llave]["Servicio"]; ?>"<?php echo $seleccion[4]; ?>><?php echo $arreglo[$llave]["Servicio"]; ?></option>
<?php
            
}
        } else {
?>
                                <option value="0">&nbsp;</option>
<?php
        
}
?>
                            </select></p>
                        </div>
                    </div>
                    <div style="clear: both; font-size: 1px; width: 100%;">&nbsp;</div>
                </div>
                <div style="clear: both; width: 100%;">
                    <div style="float: left; width: 30%;">
                        <div style="float: none; width: 100%;">
                            <p><label for="lb_acomodacion"><abbr lang="es" title="Habitación">Habit.</abbr> / Acomodación :</label></p>
                        </div>
                    </div>
<?php
        $bloques 
= array(
            
0 => "SELECT DISTINCT ac.id AS id, ac.nombre AS nombre FROM acomodaciones ac INNER JOIN tarifarios t",
            
1 => "ON (t.acomodacion = ac.id) INNER JOIN servicios s ON (t.servicio = s.id) WHERE s.estado = 1 AND s.eliminado = 0",
            
2 => "AND s.proveedor = {$datos["Servicios"][$datos["PSID"]]["Proveedor"]} AND s.ciudad = {$datos["Servicios"][$datos["PSID"]]["Ciudad"]}",
            
3 => "AND s.tiposervicio = {$datos["Servicios"][$datos["PSID"]]["TipoServicio"]} AND s.categoriaservicio = {$datos["Servicios"][$datos["PSID"]]["CategoriaServicio"]}",
            
4 => "AND s.id = {$datos["Servicios"][$datos["PSID"]]["Servicio"]} ORDER BY ac.nombre"
        
);
        
$arreglo = array();
        
$sql = implode(" ", $bloques);
        
$rs = mysql_query($sql, $cn);
        
$encontrados = mysql_num_rows($rs);
        if (
$encontrados) {
            while (
$ma = mysql_fetch_array($rs)) {
                
$arreglo[$ma["id"]] = $ma["nombre"];
            }
            
$ma = "";
        }
        
mysql_free_result($rs);
?>
                    <div style="float: left; width: 70%;">
                        <div style="float: none; width: 100%;">
                            <p><select name="sel_acomodaciones" id="lb_acomodacion" class="ComboBox" style="width: 320px;" tabindex="<?php echo $tab_index++; ?>">
<?php
        
if (count($arreglo)) {
            
$llaves = array_keys($arreglo);
            foreach (
$llaves as $llave) {
                if (
$llave == $datos["Servicios"][$datos["PSID"]]["Acomodacion"]) {
                    
$seleccion[5] = " selected=\"selected\"";
                } else {
                    
$seleccion[5] = "";
                }
                if (
$arreglo[$llave] == "[Variable]") {
                    
$acomodacion = "&nbsp;";
                } else{
                    
$acomodacion = "{$arreglo[$llave]}";
                }
?>
                                <option value="<?php echo $llave; ?>"<?php echo $seleccion[5]; ?>><?php echo $acomodacion; ?></option>
<?php
            
}
        } else {
?>
                                <option value="0">&nbsp;</option>
<?php
        
}
?>
                            </select></p>
                        </div>
                    </div>
                    <div style="clear: both; font-size: 1px; width: 100%;">&nbsp;</div>
                </div>
                <div style="clear: both; font-size: 1px; width: 100%;">&nbsp;</div>
                
<?php
    mysql_close
($cn);
?>
__________________
"Viajando en el espacio profundo, de nova en nova, y sorteando a veces uno que otro agujero negro..." Peru@D
  #7 (permalink)  
Antiguo 27/05/2011, 10:58
Avatar de rfadgrmm  
Fecha de Ingreso: junio-2009
Mensajes: 74
Antigüedad: 17 años, 3 meses
Puntos: 1
Pregunta Respuesta: Jquery - Combos Multiples

Continuación: archivo bin/class.selector.servicios.php
Lo invoco para que cambie los valores de cada combo. Es invocado en mods/cambio.servicios.php y en mods/combos.cambio.servicios.php

Código PHP:
<?php
    
class SelectorProgramaServicios {
        
        public 
$seleccion = 0;
        public 
$programa = 0;
        public 
$origen = 0;
        
        public 
$datos = array();
        public 
$bases = array();
        
        
//SERVICIO BASE...
        
public function ServicioBase($cn) {
            
            
$origen = $this->origen;
            
            switch (
$origen) {
                case 
1:
                    
$this->ProgramaServicio($cn);
                    break;
                default:
                    
$this->Proveedor($cn);
                    
$this->Ciudad($cn);
                    
$this->TipoServicio($cn);
                    
$this->CategoriaServicio($cn);
                    
$this->Servicio($cn);
                    
$this->Acomodaciones($cn);
                    break;
            }
            
            return 
$this->datos;
        }
        
        
//SELECCION DE DATOS DEL SERVICIO...
        
public function Selecciones($cn) {
            
            
$seleccion = $this->seleccion;
            
            switch (
$seleccion) {
                case 
1:
                    
$this->Ciudad($cn);
                    
$this->TipoServicio($cn);
                    
$this->CategoriaServicio($cn);
                    
$this->Servicio($cn);
                    
$this->Acomodaciones($cn);
                    break;
                case 
2:
                    
$this->TipoServicio($cn);
                    
$this->CategoriaServicio($cn);
                    
$this->Servicio($cn);
                    
$this->Acomodaciones($cn);
                    break;
                case 
3:
                    
$this->CategoriaServicio($cn);
                    
$this->Servicio($cn);
                    
$this->Acomodaciones($cn);
                    break;
                case 
4:
                    
$this->Servicio($cn);
                    
$this->Acomodaciones($cn);
                    break;
                case 
5:
                    
$this->Acomodaciones($cn);
                    break;
            }
            
            return 
$this->datos;
        }
        
        
//PROVEEDOR...
        
private function Proveedor($cn) {
            
            
$datos = $this->datos;
            
$origen = $this->origen;
            
            
$llaves = array_keys($datos["Servicios"]);
            foreach (
$llaves as $llave) {
                
$PVSID = $llave;
            }
            
            switch (
$origen) {
                case 
1:
                    
$limite = "AND s.tiposervicio NOT IN (2)";
                    break;
                default:
                    
$limite = "";
                    break;
            }
            
$bloques = array(
                
0 => "SELECT DISTINCT p.id AS id",
                
1 => "FROM proveedores p INNER JOIN servicios s ON (s.proveedor = p.id)",
                
2 => "INNER JOIN tarifarios t ON (s.id = t.servicio) WHERE s.estado = 1 AND s.eliminado = 0",
                
3 => "{$limite}",
                
4 => "ORDER BY p.nombrecomercial LIMIT 1"
            
);
            
$sql = implode(" ", $bloques);
            
$rs = mysql_query($sql, $cn);
            while (
$ma = mysql_fetch_array($rs)) {
                
$datos["Servicios"][$PVSID]["Proveedor"] = $ma["id"];
            }
            
$ma = "";
            
mysql_free_result($rs);
            
            
$this->datos = $datos;
        }
        
        
//CIUDAD...
        
private function Ciudad($cn) {
            
            
$datos = $this->datos;
            
$origen = $this->origen;
            
            
$llaves = array_keys($datos["Servicios"]);
            foreach (
$llaves as $llave) {
                
$PVSID = $llave;
            }
            
            switch (
$origen) {
                case 
1:
                    
$limite = "AND s.tiposervicio NOT IN (2)";
                    break;
                default:
                    
$limite = "";
                    break;
            }
            
$bloques = array(
                
0 => "SELECT DISTINCT c.id AS id",
                
1 => "FROM ciudades c INNER JOIN servicios s ON (s.ciudad = c.id)",
                
2 => "INNER JOIN tarifarios t ON (s.id = t.servicio) WHERE s.estado = 1",
                
3 => "AND s.eliminado = 0 AND s.proveedor = {$datos["Servicios"][$PVSID]["Proveedor"]}",
                
4 => "{$limite}",
                
5 => "ORDER BY c.nombre LIMIT 1"
            
);
            
$sql = implode(" ", $bloques);
            
$rs = mysql_query($sql, $cn);
            while (
$ma = mysql_fetch_array($rs)) {
                
$datos["Servicios"][$PVSID]["Ciudad"] = $ma["id"];
            }
            
$ma = "";
            
mysql_free_result($rs);
            
            
$this->datos = $datos;
        }
        
        
//TIPO DE SERVICIO...
        
private function TipoServicio($cn) {
            
            
$datos = $this->datos;
            
$origen = $this->origen;
            
            
$llaves = array_keys($datos["Servicios"]);
            foreach (
$llaves as $llave) {
                
$PVSID = $llave;
            }
            
            switch (
$origen) {
                case 
1:
                    
$limite = "AND ts.id NOT IN (2)";
                    break;
                default:
                    
$limite = "";
                    break;
            }
            
$bloques = array(
                
0 => "SELECT DISTINCT ts.id AS id",
                
1 => "FROM tiposservicio ts INNER JOIN servicios s ON (s.tiposervicio = ts.id)",
                
2 => "INNER JOIN tarifarios t ON (s.id = t.servicio) WHERE s.estado = 1 AND",
                
3 => "s.eliminado = 0 AND s.proveedor = {$datos["Servicios"][$PVSID]["Proveedor"]} AND",
                
4 => "s.ciudad = {$datos["Servicios"][$PVSID]["Ciudad"]}",
                
5 => "{$limite}",
                
6 => "ORDER BY ts.nombre LIMIT 1"
            
);
            
$sql = implode(" ", $bloques);
            
$rs = mysql_query($sql, $cn);
            while (
$ma = mysql_fetch_array($rs)) {
                
$datos["Servicios"][$PVSID]["TipoServicio"] = $ma["id"];
            }
            
$ma = "";
            
mysql_free_result($rs);
            
            
$this->datos = $datos;
        }
        
        
//CATEGORIA DEL SERVICIO...
        
private function CategoriaServicio($cn) {
            
            
$datos = $this->datos;
            
            
$llaves = array_keys($datos["Servicios"]);
            foreach (
$llaves as $llave) {
                
$PVSID = $llave;
            }
            
            
$bloques = array(
                
0 => "SELECT DISTINCT cs.id AS id FROM categoriasservicio cs",
                
1 => "INNER JOIN servicios s ON (s.categoriaservicio = cs.id) INNER JOIN tarifarios t ON (s.id = t.servicio)",
                
2 => "WHERE s.estado = 1 AND s.eliminado = 0 AND s.proveedor = {$datos["Servicios"][$PVSID]["Proveedor"]}",
                
3 => "AND s.ciudad = {$datos["Servicios"][$PVSID]["Ciudad"]} AND s.tiposervicio = {$datos["Servicios"][$PVSID]["TipoServicio"]}",
                
4 => "ORDER BY cs.id DESC LIMIT 1"
            
);
            
$sql = implode(" ", $bloques);
            
$rs = mysql_query($sql, $cn);
            while (
$ma = mysql_fetch_array($rs)) {
                
$datos["Servicios"][$PVSID]["CategoriaServicio"] = $ma["id"];
            }
            
$ma = "";
            
mysql_free_result($rs);
            if (
$datos["Servicios"][$PVSID]["CategoriaServicio"]) {
                
//TODO OK...
            
} else {
                
$datos["Servicios"][$PVSID]["CategoriaServicio"] = 0;
            }

            
$this->datos = $datos;
        }
        
        
//SERVICIO...
        
private function Servicio($cn) {
            
            
$datos = $this->datos;
            
            
$llaves = array_keys($datos["Servicios"]);
            foreach (
$llaves as $llave) {
                
$PVSID = $llave;
            }
            
            
$bloques = array(
                
0 => "SELECT DISTINCT s.id AS id, s.valorservicio AS valorservicio, s.precioobligatorio AS obligatorio",
                
1 => "FROM servicios s INNER JOIN tarifarios t ON (s.id = t.servicio) WHERE s.estado = 1 AND",
                
2 => "s.eliminado = 0 AND s.proveedor = {$datos["Servicios"][$PVSID]["Proveedor"]}",
                
3 => "AND s.ciudad = {$datos["Servicios"][$PVSID]["Ciudad"]}",
                
4 => "AND s.tiposervicio = {$datos["Servicios"][$PVSID]["TipoServicio"]}",
                
5 => "AND s.categoriaservicio = {$datos["Servicios"][$PVSID]["CategoriaServicio"]}",
                
5 => "ORDER BY s.descripcion LIMIT 1"
            
);
            
$sql = implode(" ", $bloques);
            
$rs = mysql_query($sql, $cn);
            while (
$ma = mysql_fetch_array($rs)) {
                
$datos["Servicios"][$PVSID]["Servicio"] = $ma["id"];
                
$datos["Servicios"][$PVSID]["ValorServicio"] = $ma["valorservicio"];
                
$datos["Servicios"][$PVSID]["Obligatorio"] = $ma["obligatorio"];
            }
            
$ma = "";
            
mysql_free_result($rs);
            
            
$this->datos = $datos;
        }
        
        
//HABITACION / ACOMODACION...
        
private function Acomodaciones($cn) {
            
            
$datos = $this->datos;
            
            
$llaves = array_keys($datos["Servicios"]);
            foreach (
$llaves as $llave) {
                
$PVSID = $llave;
            }
            
            
$bloques = array(
                
0 => "SELECT DISTINCT ac.id AS id FROM acomodaciones ac INNER JOIN tarifarios t",
                
1 => "ON (t.acomodacion = ac.id) INNER JOIN servicios s ON (t.servicio = s.id) WHERE s.estado = 1 AND s.eliminado = 0",
                
2 => "AND s.proveedor = {$datos["Servicios"][$PVSID]["Proveedor"]} AND s.ciudad = {$datos["Servicios"][$PVSID]["Ciudad"]}",
                
3 => "AND s.tiposervicio = {$datos["Servicios"][$PVSID]["TipoServicio"]} AND s.categoriaservicio = {$datos["Servicios"][$PVSID]["CategoriaServicio"]}",
                
4 => "AND s.id = {$datos["Servicios"][$PVSID]["Servicio"]} ORDER BY ac.nombre LIMIT 1"
            
);
            
$sql = implode(" ", $bloques);
            
$rs = mysql_query($sql, $cn);
            while (
$ma = mysql_fetch_array($rs)) {
                
$datos["Servicios"][$PVSID]["Acomodacion"] = $ma["id"];
            }
            
$ma = "";
            
mysql_free_result($rs);
            
            
$this->datos = $datos;
        }
    }
?>
Bueno, después de haber publicado todos los archivos necesarios, el punto es que al llamar a la funcion $("#lb_proveedor").change() en JQuery, lo hace bien, pero solo lo hace una vez, lo mismo para con $("#lb_ciudad").change(), basta que se invoque a cualquiera de los dos, ya no vuelve a ejecutarse el $.post. Todo eso es desde servicios.php. El resultado del JQuery se imprime en un div de nombre "frm_servicios".

No completé el resto de los eventos para cada combo, ya que si funciona una sola vez, es que hay algo que está mal. Agradesco toda respuesta de antemano a mi consulta...

Saludos...
__________________
"Viajando en el espacio profundo, de nova en nova, y sorteando a veces uno que otro agujero negro..." Peru@D

Etiquetas: ajax, combos
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta

SíEste tema le ha gustado a 2 personas




La zona horaria es GMT -6. Ahora son las 17:48.