1
Hello I’m doing a system that lists in the database the latest updates , even it’s all right , only I wanted to print in the table the number of total updates that the user did . How can I do that ? Thanks in advance .
Type more or less using SELECT COUNT( * )
That’s the code that makes the Foreach
<?php
$data = $_POST["data"];
$codusuario = $_POST["codusuario"];
$cRelatorios = new cRelatorios();
$relatorio = $cRelatorios->RetornaAtualizacoesFuncionarios($data,$codusuario);
//echo "<pre>"; print_r($relatorio);
if(!empty($relatorio)){
Foreach($relatorio as $value){
// echo "<pre>"; print_r($value); exit;
echo "<tr>";
echo "<td><center>". $value["usuario"] ."</center></td>";
echo "<td><center>". $value["data"] ."</center></td>";
echo "<td><center>". $value["codigo"] ."</center></td>";
echo "<td>". $value["nome"] ."</td>";
echo "<td>". $value[""] ."</td>";
echo count($relatorio);//Quero que imprima só uma vez dentro do <td>
echo "</tr>";
}
}
?>
And this is part of my PDO Query
public function RetornaAtualizacoesFuncionarios($data,$codusuario){
$WHERE = array() ;
if( !empty( $codusuario ) ) {$WHERE[] = "codusuario = $codusuario";};
if( !empty( $data ) ) {$WHERE[] = "DATE_FORMAT(data,'%Y-%m') = '$data'";};
$WHERE[] = "tipregistro = 'mysql'ORDER BY funcionarios.data DESC";
try {
$Query = "SELECT
COUNT(usuario) as qtd,
DISTINCT(funcionarios.usuario),
date_format(funcionarios.data,'%d/%m/%Y %H:%i:%s') as data ,
codigo,
nome
FROM funcionarios
";
if( !empty($WHERE) )$Query .= ' WHERE '.implode(' AND ', $WHERE );
// echo "<pre>"; print_r($Query);
include_once $_SESSION['pmodel'].'/mysqlconnection_class.php';
$p_sql = MysqlConnection::getInstance()->prepare($Query);
$_retorno = array();
if($p_sql->execute()) {
while ($_result = $p_sql->fetch(PDO::FETCH_ASSOC)) {
$_retorno[] = $_result;
}
}
return $_retorno;
} catch (PDOException $e) {
echo $e->getMessage();
}
}
}
group your updates of each user and then see the amount there is
– Fbor
@Gumball but how do I publish the result along with foreach tags ?
– allan araujo
@Fbor It would be like for a reply as I could do it ?
– allan araujo