PHP - Contar los registros del Rango entre dos fechas con calendario (datepicker)

 
Vista:

Contar los registros del Rango entre dos fechas con calendario (datepicker)

Publicado por Juanky (1 intervención) el 22/05/2014 19:30:24
Hola espero me puedan ayudar, quisiera extraer el numero de registros desde una tabla entre un rango de dos fechas con la ayuda de un calendario, miren tengo este código pero no se que falta, help me please....

// Este es mi index, junto con el resto del código
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
<?php
require("../mod_configuracion/conexion.php");
require("../temas/encabezado.php");
?>
<html>
<head>
<title>Servicios Medicos</title>
<style type="text/css">
div {
display: none;
}
table.main {
  width: 100%;
	}
table.main td {
	border-width: 1px 1px 1px 1px;
	padding: 1px 1px 1px 1px;
    font-family: verdana,arial, helvetica,  sans-serif;
    font-size: 11px;
}
table.main th {
	border-width: 1px 1px 1px 1px;
	padding: 0px 0px 0px 0px;
 
}
table.main a{TEXT-DECORATION: none;}
 
</style>
<script language="javascript" src="date-picker6.js"></script>
 
</head>
<body >
<form name=f1 action=form-data.php method=post>
<input type=text name=t1 id=t1>
 <img src='calendar.jpg'  onClick="start_cal('t1','calendar1');";>
<div id="calendar1" style="position: absolute;top: 230px;left: 5px;z-index:1;"></div>
 
 
<input type=text id=t2 name=t2>
 <img src='calendar.jpg'  onClick="start_cal('t2','calendar2');";>
<div id="calendar2" style="position: absolute; top: 230px;left: 220px;z-index:1;"></div>
<input type=submit value=Submit>
</form>
<br><br><br><br><br><br><br>
<a href=index.php><h5>Reiniciar  Calendario</h5></a></center>
<br><br><br><br><br><br><br>
<center><a href="../mod_inicio/index.php" rel='nofollow'><h4> Regresar a la Página Principal</h4></a></center>
</body>
</html>
<?php
require("../temas/PieDePagina.php");
?>


form-data.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
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
 
<head>
<title>Servicios Medicos</title>
</head>
<body>
<?Php
echo "t1 = ".$_POST['t1'] . " & t2= ".$_POST['t2'];
 
$conectar=mysql_connect('localhost','root','');
if($conectar=NULL)
{
printf("Error al conectar a la Base de datos");
}
 
mysql_select_db('serviciosmedicos');
 
//$resultado=mysql_query("SELECT * FROM consulta WHERE Fecha BETWEEN '".$REQUEST['$Inicio']."' AND '".$REQUEST['$Final']."'");
$resultado=mysql_query("SELECT COUNT(*) FROM consulta WHERE Fecha BETWEEN 't1' AND 't2'");
 
if($row=mysql_fetch_array($resultado)){
echo "<table border='1' align='center'>\n";
echo "<tr><td>Total de Consultas</td><td>Fecha</td></tr>\n";
do{
echo "<tr><td><td>".$row["Fecha"]."</td></td></tr> \n";
}while($row=mysql_fetch_array($resultado));
echo "</table>\n";
}
else{
echo "<center>No se ha encontrado ningun registro detro de ese rango...</center>";
}
?>
<br><br>
<INPUT TYPE="button" VALUE="Back" onClick="history.go(-1);">
<br>
</body>
</html>

date-picker6.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
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
///////// Collecting Month name /////////////
function show_month(month){
 
var month_name=new Array(12);
month_name[0]="Ene";
month_name[1]="Feb";
month_name[2]="Marz";
month_name[3]="Abril";
month_name[4]="Mayo";
month_name[5]="Junio";
month_name[6]="Julio";
month_name[7]="Agos";
month_name[8]="Sept";
month_name[9]="Octu";
month_name[10]="Nov";
month_name[11]="Dic";
 
return month_name[month];
}
///// End of collecting month name ////////////
 
//// Collect all date variables /////////////
function cal(chm,chy,month,year,bt,sub){
//alert('chm : ' + chm + ' chy ' + chy + ' month ' + month + ' year ' + year + ' bt ' + bt + ' sub ' + sub);
month=month + chm;
year=year + chy;
dt=new Date(year, month, 01);// Date object
var year=dt.getFullYear(); // read the current year
var display_month=dt.getMonth();
var return_month=display_month +1;
var display_month_name=show_month(display_month);
var first_day=dt.getDay(); //, first day of present month
 
dt.setMonth(month+1,0); // Set to next month and one day backward.
var last_date=dt.getDate(); // Last date of present month
///// End of date variables ////////////
///// Start lower and upper date matching logic /////
/// if 2nd calendar is used  or TO date is used //
if(bt=='t2'){
var check_type='low_side';
var t1=document.getElementById('t1').value
t1=t1.split('-');
//alert(t1[1]);
dt_t1=new Date(t1[0],t1[1],t1[2]);
dt_t_tm=dt_t1.getTime();
}
//// if 1st calendar is used or FROM date is used  ////
if(bt=='t1'){
var check_type='high_side';
var t2=document.getElementById('t2').value
t2=t2.split('-');
//alert(t1[1]);
dt_t2=new Date(t2[0],t2[1],t2[2]);
dt_t_tm=dt_t2.getTime();
}
////////// end of 1st calendar //////
 
 
//// End of lower and upper date matching logic /////
var dy=1; // day variable for adjustment of starting date.
// Top display Links with present Month & year // 
var str1="<td><a href=# onclick=show_cal(0,-1," + display_month + "," + year + ",'" + bt + "','" + sub + "');><< </a> </td><td>   <a href=# onclick=show_cal(-1,0," + display_month + "," + year + ",'" + bt + "','"+ sub + "');><</a> </td><td> "+ display_month_name +"</td><td> " + year + " </td><td align=right><a href=# onclick=show_cal(1,0," + display_month + "," + year + ",'" + bt +"','" + sub + "');>></a> </td><td> <a href=# onclick=show_cal(0,1," + display_month + "," + year + ",'" + bt +"','" + sub + "');>>></a></td>";
// End of top display links /////
 
// Display calendar body ////
var str = '';
str = "<table class='main' ><tr> " + str1 + "  <td  align=right>";
str += " <a href=# onclick=\"close_cal('" + sub +"' );\";>X</a></td></tr>";  // adding the close button. 
str +="<tr><th>Lun</th><th>Mar</th><th>Mie</th><th>Jue</th>";
str +="<th>Vie</th><th>Sab</th><th>Dom</th></tr>";
 
for(i=0;i<=41;i++){
if((i%7)==0){str = str + "</tr><tr>";} // if week is over then start a new line
if((i>= first_day) && (dy<= last_date)){
//// display the date ///
/// create date object ///
var dt_today = new Date(year,return_month,dy);
var dt_today_tm=dt_today.getTime();
switch(check_type)
{
case 'low_side':
if(dt_today_tm < dt_t_tm) {
str = str + "<td >"+ dy +"</td>";
}else{
str = str + "<td bgcolor='#ccffcc'><a href=# onclick=return_value(" + return_month + "," + dy + ","+ year + ",'"+ bt +"','" + sub + "');> "+ dy +"</a></td>";
}
dy=dy+1;
break;
////////
case 'high_side':
if(dt_today_tm > dt_t_tm) {
str = str + "<td >"+ dy +"</td>";
}else{
str = str + "<td bgcolor='#ccffcc'><a href=# onclick=return_value(" + return_month + "," + dy + ","+ year + ",'"+ bt +"','" + sub + "');> "+ dy +"</a></td>";
}
dy=dy+1;
break;
//////////////// 
default:
str = str + "<td bgcolor='#ccffcc'><a href=# onclick=return_value(" + return_month + "," + dy + ","+ year + ",'"+ bt +"','" + sub + "');> "+ dy +"</a></td>";
dy=dy+1;
break;
} // end of switch 
 
 
////////// end of date display ///
}else {str = str + "<td>*</td>";} // Blank dates.
} // end of for loop
 
str = str + "</tr></table>";
//alert(str);
return str;
}
 
function show_cal(chm, chy,month,year,bt,sub) {
document.getElementById(sub).innerHTML = cal(chm,chy,month,year,bt,sub);
document.getElementById(sub).style.display = 'inline';
}
//// Stop displaying calendar ///////////
function close_cal(sub) {
document.getElementById(sub).style.display = 'none';
}
// 
function start_cal(bt,sub) {
var dt_object=new Date();
var month=dt_object.getMonth();
var year=dt_object.getFullYear();
show_cal(0,0,month,year,bt,sub);
}
 
function return_value(month,dt,year,bt,sub){
document.getElementById(bt).value=year + '-' + month + '-' + dt   ;
close_cal(sub);
month = month -1 ; // Month adjustment 
if(bt=='t1'){
//start_cal('t2','calendar2');
show_cal(0,0,month,year,'t2','calendar2');
}
//if(bt=='t2'){
//show_cal(0,0,month,year,'t1','calendar1');
//}
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder