mi estructura de BD es la siguiente
Nombre: ethcacique
campos
Date
amount
transaccion
Donde amount es el monto en cuestion donde quiisera buscar y el filtro me devolviera el monto total de la sumatoria filtrada
Código PHP :
<?php require_once('../../Connections/Miarroba.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $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; } } mysql_select_db($database_Miarroba, $Miarroba); $query_ethcacique = "SELECT * FROM ethcacique"; $ethcacique = mysql_query($query_ethcacique, $Miarroba) or die(mysql_error()); $row_ethcacique = mysql_fetch_assoc($ethcacique); $totalRows_ethcacique = mysql_num_rows($ethcacique); $colname_busqueda = "-1"; if (isset($_GET['buscar'])) { $colname_busqueda = $_GET['buscar']; } mysql_select_db($database_Miarroba, $Miarroba); $query_busqueda = sprintf("SELECT * FROM ethcacique WHERE id = %s", GetSQLValueString($colname_busqueda, "int")); $busqueda = mysql_query($query_busqueda, $Miarroba) or die(mysql_error()); $row_busqueda = mysql_fetch_assoc($busqueda); $totalRows_busqueda = mysql_num_rows($busqueda); ?> <?php $result = mysql_query("SELECT SUM(amount) as total FROM ethcacique"); $row = mysql_fetch_array($result, MYSQL_ASSOC); ?> <!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>..:: Kerberos ::..</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.5/css/bootstrap.min.css" /> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.5.0/css/bootstrap-datepicker.min.css" /> <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.5.0/js/bootstrap-datepicker.min.js"></script> <style type="text/css"> <!-- body,td,th { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; } .Estilo1 { color: #0066FF; font-weight: bold; font-size: 11px; } .Estilo3 { font-size: 14px; font-weight: bold; } .Estilo4 { font-size: 11px; font-weight: bold; } .Estilo5 {color: #FF0000} .Estilo8 {color: #FFFFFF; font-weight: bold; } --> </style></head> <body> <p class="Estilo3">Sistema Administrativo</p> <p class="Estilo3"> </p> <p class="Estilo1">Transacciones Cacique ETH</p> <p class="Estilo4">Transaction Address: <span class="Estilo5">0x7f01921AF6DbcF81086c5CF88aA7c93f66527835</span></p> <p> </p> <p><div class="alert alert-danger">No existe Historial de Transacciones</div></p> <div align="center"> <table width="916" border="1"> <tr> <td width="451" height="23" bgcolor="#CCCCCC"><div align="center"><strong>Transacction</strong></div></td> <td width="244" bgcolor="#CCCCCC"><div align="center"><strong>Amount</strong></div></td> <td width="199" bgcolor="#CCCCCC"><div align="center"><strong>Date</strong></div></td> </tr> <tr> <td height="18"><div align="center"><?php echo $row_ethcacique['transaction']; ?></div></td> <td><div align="center"><?php echo $row_ethcacique['amount']; ?></div></td> <td><div align="center"><?php echo $row_ethcacique['date']; ?></div></td> </tr> </table> </div> <p> </p> <p> </p> <div align="center"> <table width="734" border="1"> <tr> <td width="369"><span class="Estilo4">Total Transacciones <span class="Estilo5"><?php echo $totalRows_ethcacique ?></span></span> </td> <td width="349"><div align="center"><span class="Estilo4">Total Amount </span><?php echo $row["total"];?> </div></td> </tr> </table> </div> <p> </p> <p> </p> <p> </p> <form id="busqueda" name="busqueda" method="get" action="cacique.php"> <p> <label> <input type="text" name="buscar" id="buscar" /> </label> <label> <input type="submit" name="Buscar" id="Buscar" value="Buscar" /> </label> </p> <p> </p> <?php if ($totalRows_busqueda > 0) { // Show if recordset not empty ?> <div align="center"> <table width="672" border="1"> <tr bgcolor="#990000"> <td width="147"><div align="center" class="Estilo8">Fecha</div></td> <td width="163"><div align="center" class="Estilo8">Amount</div></td> <td width="340"><div align="center" class="Estilo8">Transaction</div></td> </tr> <tr> <td><?php echo $row_busqueda['date']; ?></td> <td><?php echo $row_busqueda['amount']; ?></td> <td><?php echo $row_busqueda['transaction']; ?></td> </tr> </table> <br /> </div> <p><strong> Toral Registros Devueltos</strong> <span class="Estilo5"><?php echo $totalRows_busqueda ?></span> </p> <?php } // Show if recordset not empty ?> <p> </p> </form> <p> </p> </body> </html> <?php mysql_free_result($ethcacique); mysql_free_result($busqueda); ?>