Created
July 15, 2015 16:20
-
-
Save porfidev/47c95b5d0a5c8ba7854c to your computer and use it in GitHub Desktop.
selects nitramara
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Created by PhpStorm. | |
* User: elporfirio | |
* Date: 15/07/2015 | |
* Time: 10:44 AM | |
*/ | |
class MySQL | |
{ | |
var $conexion; | |
function MySQL() | |
{ | |
if (!isset($this->conexion)) { | |
$this->conexion = (mysql_connect('localhost', 'root', '')) or die(mysql_error()); | |
mysql_select_db('combobox', $this->conexion) or die(mysql_error()); | |
} | |
} | |
function consulta($consulta) | |
{ | |
$resultado = mysql_query($consulta, $this->conexion); | |
if (!$resultado) { | |
echo 'MySQL Error: ' . mysql_error(); | |
exit; | |
} | |
return $resultado; | |
} | |
function fetch_array($consulta) | |
{ | |
return mysql_fetch_array($consulta); | |
} | |
function num_rows($consulta) | |
{ | |
return mysql_num_rows($consulta); | |
} | |
function fetch_row($consulta) | |
{ | |
return mysql_fetch_row($consulta); | |
} | |
function fetch_assoc($consulta) | |
{ | |
return mysql_fetch_assoc($consulta); | |
} | |
} | |
class selects extends MySQL | |
{ | |
var $code = ""; | |
function cargarComunidades() | |
{ | |
$consulta = parent::consulta("SELECT departamento,com_id FROM localidad ORDER BY departamento ASC"); | |
$num_total_registros = parent::num_rows($consulta); | |
if ($num_total_registros > 0) { | |
$comunidades = []; | |
while ($comunidad = parent::fetch_assoc($consulta)) { | |
$code = $comunidad["com_id"]; | |
$name = $comunidad["departamento"]; | |
$comunidades[$code] = $name; | |
} | |
return $comunidades; | |
} else { | |
return false; | |
} | |
} | |
function cargarProvincias() | |
{ | |
$consulta = parent::consulta("SELECT municipio,prov_id FROM localidad WHERE com_id = '" . $this->code . "' ORDER BY municipio ASC "); | |
$num_total_registros = parent::num_rows($consulta); | |
if ($num_total_registros > 0) { | |
$provincias = []; | |
while ($provincia = parent::fetch_assoc($consulta)) { | |
$code = $provincia["prov_id"]; | |
$name = $provincia["municipio"]; | |
$provincias[$code] = $name; | |
} | |
return $provincias; | |
} else { | |
return false; | |
} | |
} | |
function cargarLocalidades() | |
{ | |
$consulta = parent::consulta("SELECT nombre,loc_id FROM localidad WHERE prov_id = '" . $this->code . "'"); | |
$num_total_registros = parent::num_rows($consulta); | |
if ($num_total_registros > 0) { | |
$localidades = []; | |
while ($localidad = parent::fetch_assoc($consulta)) { | |
$code = $localidad["loc_id"]; | |
$name = $localidad["nombre"]; | |
$localidades[$code] = $name; | |
} | |
return $localidades; | |
} else { | |
return false; | |
} | |
} | |
## ESTA nO SE DE QUE DEPENDA POR ESO NI IDEA :P | |
## POR QUE TE TRAES EL CODIGO SI NO LO UTILIZAS AQuI $this->code | |
function cargarLocalidadesB() | |
{ | |
$consulta = parent::consulta("SELECT sector,sect_id FROM localidad"); | |
$num_total_registros = parent::num_rows($consulta); | |
if ($num_total_registros > 0) { | |
$localidades1 = []; | |
while ($localidad1 = parent::fetch_assoc($consulta)) { | |
$code = $localidad1["sect_id"]; | |
$name = $localidad1["sector"]; | |
$localidades1[$code] = $name; | |
} | |
return $localidades1; | |
} else { | |
return false; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Created by PhpStorm. | |
* User: elporfirio | |
* Date: 15/07/2015 | |
* Time: 10:42 AM | |
*/ | |
include("class.mysql.php"); | |
$tipo = $_POST['obtener']; | |
$oSelects = new selects(); | |
##Cargar Comunidades | |
if($tipo === 'comunidades'){ | |
$comunidades = $oSelects->cargarComunidades(); | |
foreach($comunidades as $key=>$value) | |
{ | |
echo "<option value=\"$key\">$value</option>"; | |
} | |
} else if($tipo === 'provincias'){ | |
$oSelects->code = $_GET["code"]; | |
$provincias = $oSelects->cargarProvincias(); | |
foreach($provincias as $key=>$value) | |
{ | |
echo "<option value=\"$key\">$value</option>"; | |
} | |
} else if($tipo === 'localidadA'){ | |
$oSelects->code = $_GET["code"]; | |
$localidadA = $oSelects->cargarLocalidades(); | |
foreach($localidadA as $key=>$value) | |
{ | |
echo "<option value=\"$key\">$value</option>"; | |
} | |
} else if($tipo === 'localidadB'){ | |
//$oSelects->code = $_GET["code"]; | |
$localidadB = $oSelects->cargarLocalidadesB(); | |
foreach($localidadB as $key=>$value) | |
{ | |
echo "<option value=\"$key\">$value</option>"; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head lang="en"> | |
<meta charset="UTF-8"> | |
<title></title> | |
</head> | |
<body> | |
<form method="post" action="pruebaenvio.php" width="40%"> | |
<dl> | |
<dt>Ubicación:</dt> | |
<dd>Comunidad:</dd> | |
<dd> | |
<select name="comunidad" id="comunidad"> | |
<option value="">Selecciona una...</option> | |
</select> | |
</dd> | |
<dd>Provincia:</dd> | |
<dd> | |
<select name="provincia" id="provincia"> | |
<option value="">Selecciona una...</option> | |
</select> | |
</dd> | |
<dd>Localidad:</dd> | |
<dd> | |
<select name="localidadA" id="localidadA"> | |
<option value="">Selecciona una...</option> | |
</select> | |
</dd> | |
<dd>Localidad1:</dd> | |
<dd> | |
<select name="localidadB" id="localidadB"> | |
<option value="">Selecciona una...</option> | |
</select> | |
</dd> | |
</dl> | |
<div class="botones"> | |
<button type="submit">Enviar</button> | |
</div> | |
</form> | |
<script type="text/javascript"> | |
function disableAllSelects() { | |
$('#comunidad').val(''); | |
$('#provincia, #localidadA, #localidadB').attr('disabled', true); | |
} | |
function cargar_comunidades() { | |
$.get("funciones.php", {obtener: 'comunidades'}, function (resultado) { | |
if (resultado == false) { | |
alert("Error"); | |
} | |
else { | |
$('#comunidad').append(resultado); | |
} | |
}); | |
} | |
function dependencia_provincia(comunidad_code) { | |
$.get("funciones.php", {obtener: 'provincias', code: comunidad_code}, | |
function (resultado) { | |
if (resultado == false) { | |
alert("Error"); | |
} | |
else { | |
$('#provincia').append(resultado).attr("disabled", false); | |
} | |
} | |
); | |
} | |
function dependencia_localidadA(provincia_code) { | |
$.get("funciones.php", {obtener: 'localidadA', code: provincia_code}, | |
function (resultado) { | |
if (resultado == false) { | |
alert("Error"); | |
} | |
else { | |
$('#localidadA').append(resultado).attr("disabled", false); | |
} | |
} | |
); | |
} | |
function dependencia_localidadB(localidad_code) { | |
$.get("funciones.php", {obtener: 'localidadB', code: localidad_code}, | |
function (resultado) { | |
if (resultado == false) { | |
alert("Error"); | |
} | |
else { | |
$('#localidadB').append(resultado).attr("disabled", false); | |
} | |
}); | |
} | |
$(document).ready(function () { | |
disableAllSelects() | |
cargar_comunidades(); | |
$("#comunidad").on("change", function () { | |
dependencia_provincia($('#comunidad').val()); | |
}); | |
$("#provincia").on("change", function () { | |
dependencia_localidadA($('#provincia').val()); | |
}); | |
$("#localidadA").on("change", function () { | |
dependencia_localidadB($('#localidadA').val()); | |
}); | |
}); | |
</script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Created by PhpStorm. | |
* User: elporfirio | |
* Date: 15/07/2015 | |
* Time: 10:49 AM | |
*/ | |
var_dump($_POST); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment