Ver Mensaje Individual
  #3 (permalink)  
Antiguo 15/09/2010, 16:42
joy_zed
 
Fecha de Ingreso: septiembre-2010
Mensajes: 5
Antigüedad: 13 años, 7 meses
Puntos: 0
Respuesta: sumar cantidades semanalmente

Hola Hidek1,

la estructura de la tabla es la siguiente:

nombre (varchar 30);
app (varchar 30);
apm (varchar 30);
casas_con int;
casas_pre int;
casas_ven int;

casas_con,pre,ven, son los valores que recibo diario, de esos necesito la suma de acuerdo al dia. Actualmente tengo el siguiente formulario, pero no me sale los resultados que quiero, lo que hago es tomar la fecha actual, y pedir una fecha que sirva de rango para compararla con la actual. es decir, de la fecha actual menos 3 dias, por ejemplo.

<? include ("conexion_BD.php") ?>
<?php
//ConectDB($link);
$link=conectame();

$nomb = $_POST['usu'];

$result2=@mysql_query("SELECT * FROM temp_jose WHERE borra='1' ",$link);
$Y=@mysql_fetch_array($result2);

$result=@mysql_query("SELECT * FROM usuarios WHERE usuario='$Y[usuario]' ",$link);
$X=@mysql_fetch_array($result);

$result3=@mysql_query("SELECT * FROM reportes WHERE nombre_completo='$nomb' ",$link);
$Z=@mysql_fetch_array($result3);

$result4=@mysql_query("SELECT * FROM sumas WHERE nombre_completo='$nomb' ",$link);
$W=@mysql_fetch_array($result4);
?>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><link rel="stylesheet" type="text/css" href="../estilos/estilo_html.css"><link rel="stylesheet" type="text/css" href="../estilos/estilo_ligas.css"><link rel="stylesheet" href="menu_data/cbcscbinsmenu.css" type="text/css" />

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>ExE ASESORES</title>
<script language="JavaScript">
function calcula(){

$nomb = $_POST['usu'];
$d = $_POST['di'];
$m = $_POST['me'];
$a = $_POST['an'];

$d2 = $_POST['di2'];
$m2 = $_POST['me2'];
$a2 = $_POST['an2'];

$result2=@mysql_query("SELECT * FROM temp_jose WHERE borra='1' ",$link);
$Y=@mysql_fetch_array($result2);

$result=@mysql_query("SELECT * FROM usuarios WHERE usuario='$Y[usuario]' ",$link);
$X=@mysql_fetch_array($result);


$query = mysql_query("SELECT SUM(casas_consig) FROM reportes WHERE nombre_completo='$nomb' AND fecha BETWEEN '$a2-$m2-$d2' AND ''$a-$m-$d'' ");
$resultado = mysql_result($query, 0);

$query2 = mysql_query("SELECT SUM(casas_present) FROM reportes WHERE nombre_completo='$nomb' AND fecha BETWEEN '$a2-$m2-$d2' AND ''$a-$m-$d'' ");
$resultado2 = mysql_result($query2, 0);

$query3 = mysql_query("SELECT SUM(casas_present) FROM reportes WHERE nombre_completo='$nomb' AND fecha BETWEEN '$a2-$m2-$d2' AND ''$a-$m-$d'' ");
$resultado3 = mysql_result($query3, 0);


$r1=$resultado;
$r2=$resultado2;
$r3=$resultado3;


}
</script>


<style type="text/css">
<!--
a:link {
color: #0000CC;
text-decoration: none;
}
a:visited {
text-decoration: none;
color: #0000CC;
}
a:hover {
text-decoration: none;
}
a:active {
text-decoration: none;
}
.Estilo39 {font-size: 9px}
body {
background-image: url(imagenes/flux.jpg);
}
.Estilo44 {
color: #A50021;
font-weight: bold;
}
.Estilo47 {color: #333333; font-family: Calibri; font-weight: bold; }
.Estilo48 {color: #EAEAEA}
.Estilo51 {
font-family: Calibri;
font-weight: bold;
font-size: 12px;
}
.Estilo54 {font-family: Calibri; font-size: 12px; }
.Estilo62 { font-size: 12px;
font-weight: bold;
}
.Estilo63 {
font-family: Calibri;
font-size: 16px;
font-weight: bold;
}
.Estilo64 {
font-size: 24px;
font-weight: bold;
}
-->
</style>
</head>

<body onload="calcula()">

<form name="form1" method="post" action="">
<table width="900" align="center" cellpadding="0" cellspacing="0" bordercolor="#EAEAEA" background="../Imagenes/fondo03.jpg" frame="above" rules="none">
<tbody>
<tr>
<td width="175" height="19" bgcolor="#EAEAEA">&nbsp;</td>
<td width="551" bgcolor="#EAEAEA"><div align="center">
<p>&nbsp;</p>
<table width="400">
<tr>
<td colspan="2"><div align="center" class="Estilo63">Resultado de la b&uacute;squeda</div></td>
</tr>
<tr>
<td width="114"><span class="Estilo51">Asesor:</span></td>
<td width="274"><input name="nombre" type="text" id="nombre" value="<?=$Z[nombre_completo];?>" size="30"></td>
</tr>
<tr>
<td><span class="Estilo51">Fecha Actual </span></td>
<td><span class="Estilo54">
<?php
$fecha = date ("d/m/Y");
//if ($fecha == 'Tue'){$fecha='Miercoles';}

echo "Hoy es: " . $fecha;
?>
</span></td>
</tr>
</table>
<p class="Estilo64"><br>
__________________________________<br>
</p>
<table width="320" height="71">
<tr>
<td height="21" colspan="2"><div align="center" class="Estilo63">Suma de Casas en este periodo </div></td>
</tr>
<tr>
<td width="133" height="21"><span class="Estilo51">Casas Consignadas</span></td>
<td width="175"><input name="caco" type="text" id="caco" value="<?=$r1;?>" size="5"></td>
</tr>
<tr>
<td height="21"><span class="Estilo51">Casas Presentadas </span></td>
<td><input name="capr" type="text" id="capr" size="5"></td>
</tr>
<tr>
<td height="21"><span class="Estilo51">Casas Vendidas </span></td>
<td><input name="cave" type="text" id="cave" size="5"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table>
<br>
<table width="320" height="71">
<tr>
<td height="21" colspan="2"><div align="center" class="Estilo63">Total general </div></td>
</tr>
<tr>
<td width="133" height="21"><span class="Estilo51">Casas Consignadas</span></td>
<td width="175"><input name="tot1" type="text" id="tot1" value="<?=$W[total_con];?>" size="5"></td>
</tr>
<tr>
<td height="21"><span class="Estilo51">Casas Presentadas </span></td>
<td><input name="tot2" type="text" id="tot2" value="<?=$W[total_pre];?>" size="5"></td>
</tr>
<tr>
<td height="21"><span class="Estilo51">Casas Vendidas </span></td>
<td><input name="tot3" type="text" id="tot3" value="<?=$W[total_ven];?>" size="5"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table>
<p>&nbsp;</p>
</div></td>
<td width="174" bgcolor="#EAEAEA">&nbsp;</td>
</tr>
</tbody>
</table>
</form>
</body>
</html>