Hago una consulta a la tabla recibos donde filtro por nombre de comercio y por fecha
y deseo sumar el monto total de todos los recibos de la consulta y hasta ahora no lo consigo me da el total de todos los registros, Gracias de antemano a quien me pueda echar una mano.
Esta es la consulta:
Código PHP :
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$colname_recibos = "-1";
if (isset($_GET['comercio'])) {
$colname_recibos = $_GET['comercio'];
}
$colname2_recibos = "-1";
if (isset($_GET['fechapago'])) {
$colname2_recibos = $_GET['fechapago'];
}
mysql_select_db($database_usersconexion, $usersconexion);
$query_recibos = sprintf("SELECT * FROM tbrecibos WHERE comercio LIKE %s AND fechapago LIKE %s", GetSQLValueString("%" . $colname_recibos . "%", "text"),GetSQLValueString("%" . $colname2_recibos . "%", "text"));
$recibos = mysql_query($query_recibos, $usersconexion) or die(mysql_error());
$row_recibos = mysql_fetch_assoc($recibos);
$totalRows_recibos = mysql_num_rows($recibos);$colname_recibos = "-1";
if (isset($_GET['comercio'])) {
$colname_recibos = $_GET['comercio'];
}
$colname2_recibos = "-1";
if (isset($_GET['fechapago'])) {
$colname2_recibos = $_GET['fechapago'];
}
$total = 0 ;
mysql_select_db($database_usersconexion, $usersconexion);
$query_recibos = sprintf("SELECT * FROM tbrecibos WHERE comercio LIKE %s AND fechapago LIKE %s", GetSQLValueString("%" . $colname_recibos . "%", "text"),GetSQLValueString("%" . $colname2_recibos . "%", "text"));
$recibos = mysql_query($query_recibos, $usersconexion) or die(mysql_error());
$row_recibos = mysql_fetch_assoc($recibos);
$totalRows_recibos = mysql_num_rows($recibos);
Y este es el totalizador que me totaliza todos los registros y no la consulta:
Código PHP :
$query_recibos=mysql_query("SELECT * FROM tbrecibos ");
while($row_recibos=mysql_fetch_assoc($query_recibos)){
$total= $total + $row_recibos['total'];
}
echo $total //muestra la suma totalLlevo 1 dia como loco con esto.
[img]https://mail.google.com/mail/u/0/?ui=2&ik=b6e0dd5c71&view=att&th=13de7f8b5039842c&attid=0.1&disp=emb&realattid=ii_13de7f89ba16fb65&zw&atsh=1[/img]
