Consulta en solapas de un div.
Publicado por Juan Carlos (2 intervenciones) el 14/09/2012 17:11:34
Tengo tres codigos donde recojo los datos pero no funciona:
index.php
ajax.php
js.js
index.php
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<!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" />
<title>Filtro en tabla mysql con ajax php & mysql</title>
<link rel="stylesheet" type="text/css" href="assets/css/style.css"/>
<style type="text/css">
/* CSS demo */
#content{
padding:20px 0 0 10px
}
#content .filtro{
overflow:hidden;
padding-bottom:15px
}
#content .filtro select{
width:100px
}
#content .filtro ul{
list-style:none;
padding:0
}
#content .filtro li{
float:left;
display:block;
margin:0 5px
}
#content .filtro li a{
color:#006;
position:relative;
top:5px;
text-decoration:underline
}
#content .filtro li label{
float:left;
padding:4px 5px 0 0
}
#content table{
width:940px;
}
#content table th{
border:1px solid #999;
padding:8px;
background:#F8F8F8
}
#content table th span{
cursor:pointer;
padding-right:12px
}
#content table th span.asc{
background:url(assets/imgs/sorta.gif) no-repeat right center;
}
#content table th span.desc{
background:url(assets/imgs/sortd.gif) no-repeat right center;
}
#content table td{
border:1px solid #999;
padding:6px
}
#boton{
}
</style>
<link rel="stylesheet" type="text/css" href="assets/jqueryui/css/smoothness/jquery-ui-1.8.16.custom.css"/>
<script type="text/javascript" src="assets/js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="assets/jqueryui/js/jquery-ui-1.8.16.custom.min.js"></script>
<script type="text/javascript" src="assets/js/js.js"></script>
<script src="SpryAssets/SpryTabbedPanels.js" type="text/javascript"></script>
<link href="SpryAssets/SpryTabbedPanels.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top">
Consulta de Intervenciones
</div>
<div id="content">
<div class="filtro">
<form id="frm_filtro" method="post" action="">
<table width="771">
<tr>
<td width="9%" class="campo_apellidos2">Teléfonos</td>
<td width="7%"><input name="telefono" type="text" size="9" /></td>
<td width="7%"><input name="telefono2" type="text" id="telefono2" size="9" /></td>
<td width="13%"><input name="telefono3" type="text" id="telefono3" size="9" /></td>
<td width="22%"> </td>
<td width="16%" class="campo_apellidos2">NIF</td>
<td width="26%"><input name="NIF" type="text" id="NIF" size="9" /></td>
</tr>
<tr>
<td class="campo_apellidos2">Nombre</td>
<td colspan="4"><input name="nombre_apellidos" type="text" size="45" />
<td> </td>
<td> </td>
</tr>
<tr>
<td class="campo_apellidos2">Localidad</td>
<td colspan="4"><input name="poblacion" type="text" size="40" />
<span class="campo_apellidos2">C.Postal</span> <input name="cod_postal" type="text" id="cod_postal" size="5" /></td>
<td class="campo_apellidos2">Provincia</td>
<td><input name="provincia" type="text" size="9" /></td>
</tr>
<tr>
<td class="campo_apellidos2">Calle</td>
<td colspan="4"><input name="calle" type="text" id="calle" size="45" />
<span class="campo_apellidos2">Nº</span> <input name="numero" type="text" id="numero" size="5" /></td>
<td class="campo_apellidos2">Edificio</td>
<td><input name="edificio" type="text" id="edificio" size="5" /></td>
</tr>
<tr>
<td class="campo_apellidos2">Puerta</td>
<td colspan="3"><input name="puerta" type="text" id="puerta" size="5" />
<span class="campo_apellidos2"> Piso</span>
<input name="piso" type="text" id="piso" size="5" />
<span class="campo_apellidos2">Letra</span> <input name="letra" type="text" id="letra" size="5" /></td>
<td> </td>
<td><span class="campo_apellidos2">Nº Cont.Mante.</span></td>
<td><input name="mantenimiento" type="text" id="mantenimiento" size="5" /></td>
</tr>
</table>
<table width="100%">
<tr>
<th scope="col"><INPUT type="button" id="btnfiltrar"value="Iniciar Búsqueda" name="button2" onClick="window.status='You clicked the button!'; return true"></th>
</tr>
</table>
</form>
</div>
<div id="TabbedPanels1" class="TabbedPanels">
<ul class="TabbedPanelsTabGroup">
<li class="TabbedPanelsTab" tabindex="0">Usuarios</li>
<li class="TabbedPanelsTab" tabindex="0">Aparatos</li>
<li class="TabbedPanelsTab" tabindex="0">Intervenciones</li>
</ul>
<div class="TabbedPanelsContentGroup">
<div class="TabbedPanelsContent"><table cellpadding="0" cellspacing="0" id="data">
<thead>
<tr>
<th width="22%"><span title="nu_usuario">Nº Usuario</span></th>
<th width="22%"><span title="telefono">Nº Teléfono</span></th>
<th width="35%"><span title="nombre">Nombre</span></th>
<th><span title="poblacion">Localidad</span></th>
</tr>
</thead>
<tbody>
</tbody>
</table></div>
<div class="TabbedPanelsContent">
<table cellpadding="0" cellspacing="0" id="data1">
<thead>
<tr>
<th><span title="aparato">Aparato</span></th>
<th><span title="marca">Marca</span></th>
<th><span title="modelo">Modelo</span></th>
<th><span title="NUM_SERIE">Nº Serie</span></th>
<th><span title="num_PRODUCTO">COD/12NC</span></th>
<th><span title="FECHA_compra">F.Compra</span></th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
<div class="TabbedPanelsContent"> <table cellpadding="0" cellspacing="0" id="data2">
<thead>
<tr>
<th><span title="aviso">Nº Aviso</span></th>
<th><span title="usuario">Nº Usuario</span></th>
<th><span title="aparato">Aparato</span></th>
<th><span title="calle">Dirección</span></th>
<th><span title="fecha_recepcion">F.Recepción</span></th>
<th><span title="fecha_recepcion">F.Emisión</span></th>
<th><span title="sintoma">Síntoma</span></th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
</div>
</div>
<script type="text/javascript">
var TabbedPanels1 = new Spry.Widget.TabbedPanels("TabbedPanels1");
</script>
</body>
</html>
ajax.php
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
66
67
68
69
70
71
72
73
74
75
76
77
<?php
include("conexion.php");
if ($_GET["action"] == "listar")
{
// valores recibidos por POST
$vnm = $_POST['nombre_apellidos'];
$vpo = $_POST['poblacion'];
$vte = $_POST['telefono'];
$vdel = ($_POST['del'] != '' ) ? explode("/",$_POST['del']) : '';
$val = ($_POST['al'] != '' ) ? explode("/",$_POST['al']) : '';
$sql = "SELECT
U.nombre,
U.apellidos,
U.nu_usuario,
U.telefono,
D.poblacion,
A.aparato,
A.marca,
A.modelo,
A.num_serie,
A.num_producto,
A.fecha_compra,
B.num_aviso,
B.num_usuario,
D.calle,
B.fecha_recepcion,
B.fecha_emision,
B.sintoma
FROM
dir_usuarios D INNER JOIN usuarios U ON D.usuario = U.nu_usuario
INNER JOIN ap_usuarios A ON U.nu_usuario = A.num_usuario
INNER JOIN avisos B ON U.nu_usuario = B.num_usuario
WHERE
CONCAT( nombre, ' ', apellidos ) LIKE '%$vnm%'
AND telefono LIKE '%vte%'
AND poblacion LIKE '%$vpo%';
";
// Ordenar por
$vorder = $_POST['orderby'];
if($vorder != ''){
$sql .= " ORDER BY ".$vorder;
}
$query = mysql_query($sql);
$datos = array();
while($row = mysql_fetch_array($query))
{
$datos[] = array(
'nu_usuario' => $row['nu_usuario'],
'telefono' => $row['telefono'],
'nombre' => $row['nombre'],
'apellidos' => $row['apellidos'],
'poblacion' => $row['poblacion'],
'aparato' => $row['aparato'],
'marca' => $row['marca'],
'modelo' => $row['modelo'],
'num_serie' => $row['num_serie'],
'num_producto' => $row['num_producto'],
'fecha_compra' => $row['fecha_compra'],
'num_aviso' => $row['num_aviso'],
'num_usuario' => $row['num_usuario'],
'calle' => $row['calle'],
'fecha_recepcion' => $row['fecha_recepcion'],
'fecha_emision' => $row['fecha_emision'],
'sintoma' => $row['sintoma']
);
}
// convertimos el array de datos a formato json
echo json_encode($datos);
}
?>
js.js
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// JavaScript Document
var ordenar = '';
$(document).ready(function(){
// Llamando a la funcion de busqueda al
// cargar la pagina
filtrar()
var dates = $( "#del, #al" ).datepicker({
yearRange: "-50",
defaultDate: "+1w",
changeMonth: true,
changeYear: true,
onSelect: function( selectedDate ) {
var option = this.id == "del" ? "minDate" : "maxDate",
instance = $( this ).data( "datepicker" ),
date = $.datepicker.parseDate(
instance.settings.dateFormat ||
$.datepicker._defaults.dateFormat,
selectedDate, instance.settings );
dates.not( this ).datepicker( "option", option, date );
}
});
// filtrar al darle click al boton
$("#btnfiltrar").click(function(){ filtrar() });
// boton cancelar
$("#btncancel").click(function(){
$(".filtro input").val('')
$(".filtro select").find("option[value='0']").attr("selected",true)
filtrar()
});
// ordenar por
$("#data th span").click(function(){
var orden = '';
if($(this).hasClass("desc"))
{
$("#data th span").removeClass("desc").removeClass("asc")
$(this).addClass("asc");
ordenar = "&orderby="+$(this).attr("title")+" asc"
}else
{
$("#data th span").removeClass("desc").removeClass("asc")
$(this).addClass("desc");
ordenar = "&orderby="+$(this).attr("title")+" desc"
}
filtrar()
});
});
function filtrar()
{
$.ajax({
data: $("#frm_filtro").serialize()+ordenar,
type: "POST",
dataType: "json",
url: "ajax.php?action=listar",
success: function(data){
var html_user ='' ;
var html_aparato = '';
if(data.length > 0){
$.each(data, function(i,item){
html_user += '<tr>';
html_user += '<td>'+item.nu_usuario+'</td>';
html_user += '<td>'+item.telefono+'</td>';
html_user += '<td>'+item.nombre+' '+item.apellidos+'</td>';
html_user += '<td>'+item.poblacion+'</td>';
html_user += '</tr>';
html_aparato += '<tr>';
html_aparato += '<td>'+item.aparato+'</td>';
html_aparato += '<td>'+item.marca+'</td>';
html_aparato += '<td>'+item.modelo+'</td>';
html_aparato += '<td>'+item.num_serie+'</td>';
html_aparato += '<td>'+item.num_producto+'</td>';
html_aparato += '<td>'+item.fecha_compra+'</td>';
html_aparato += '</tr>';
html_avisos += '<tr>';
html_avisos += '<td>'+item.num_aviso+'</td>';
html_avisos += '<td>'+item.num_usuario+'</td>';
html_avisos += '<td>'+item.aparato+'</td>';
html_avisos += '<td>'+item.calle+'</td>';
html_avisos += '<td>'+item.fecha_recepcion+'</td>';
html_avisos += '<td>'+item.fecha_emision+'</td>';
html_avisos += '<td>'+item.sintoma+'</td>';
html_avisos += '</tr>';
});
}
if(html_user == '') html_user = '<tr><td colspan="4" align="center">No se encontraron registros..</td></tr>';
if(html_aparato == '') html_aparato = '<tr><td colspan="4" align="center">No se encontraron registros..</td></tr>';
if(html_avisos == '') html_avisos = '<tr><td colspan="4" align="center">No se encontraron registros..</td></tr>';
$("#data tbody").html(html_user);
$("#data1 tbody").html(html_aparato);
$("#data2 tbody").html(html_avisos);
}
});
}
Valora esta pregunta


0