-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathubigeo.php
More file actions
65 lines (58 loc) · 1.36 KB
/
ubigeo.php
File metadata and controls
65 lines (58 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
class UbiGeo
{
public function __construct()
{
mysql_connect('localhost', 'usuario', 'clave');
mysql_select_db('test');
}
public function cargarDepartamentos()
{
$sql = "SELECT id, desdep descri FROM departamentos";
$this->listarOptions($sql);
}
public function cargarProvincias($coddep)
{
$sql = "SELECT id, despro descri FROM provincias
WHERE departamento_id = $coddep";
$this->listarOptions($sql);
}
public function cargarDistritos($codpro)
{
$sql = "SELECT id, desdist descri FROM distritos
WHERE provincia_id = $codpro";
$this->listarOptions($sql);
}
public function cargarCentros($coddis)
{
$sql = "SELECT ce.id, CONCAT(descat, ' ', descen) descri
FROM centros ce
INNER JOIN categorias ca
ON ce.categoria_id = ca.id
WHERE distrito_id = $coddis";
$this->listarOptions($sql);
}
private function listarOptions($sql)
{
$rs = mysql_query($sql);
while($reg = mysql_fetch_assoc($rs)){
echo "<option value='{$reg['id']}'>".utf8_encode($reg['descri'])."</option>";
}
}
}
$obUbigeo = new UbiGeo();
switch ($_GET['accion']) {
case 'carga_dpto':
$obUbigeo->cargarDepartamentos();
break;
case 'carga_prov':
$obUbigeo->cargarProvincias($_GET['cd']);
break;
case 'carga_dist':
$obUbigeo->cargarDistritos($_GET['cp']);
break;
case 'carga_cent':
$obUbigeo->cargarCentros($_GET['cd']);
break;
}
?>