-2
I have a problem and I can not solve, I need to make a code that searches the data in the database and makes the total count of these data, then I need to separate them from the largest to the smallest, the big problem is that the data is repeated, then I need to count that data and then if it is greater than the quantity of the others then it appears in the ranking.
For now I have this code below but I know that there is a shorter way to do this, I need help, because there are more than 100 different data and each one can have several quantities, I need to know who is the may
$host = "localhost";
$usuario = "root";
$senha = "";
$banco = "netanalise";
$totime = strtotime("-1 days");
$data = date("Y/m/d",$totime);
$data01=date("Y/m/d");
$dataTabela=date("d/m/Y",$totime);
$cont01=1;$cont02=1;$cont03=1;$cont04=1;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//para o total
$c01= mysqli_connect($host, $usuario, $senha) or trigger_error(mysqli_error(),E_USER_ERROR);
// seleciona a base de dados em que vamos trabalhar
mysqli_select_db($c01,$banco);
// cria a instrução SQL que vai selecionar os dados
$query01 = ("SELECT * FROM net_virtua WHERE codBaixa and data BETWEEN CURRENT_DATE()-7 AND CURRENT_DATE()");
// executa a query
$dados_Ant = mysqli_query($con_Ant,$query01) or die(mysqli_error());
// transforma os dados em um array
while( $linha_cod_virtua = mysqli_fetch_assoc($dados_Ant))
{
if($linha_cod_virtua['codBaixa'] == $todos_codigos[0])
{
$dado = $cont01++;
}
else if($linha_cod_virtua['codBaixa'] == $todos_codigos[1])
{
$dado1 = $cont02++;
}
else if($linha_cod_virtua['codBaixa'] == $todos_codigos[2])
{
$dado2 = $cont03++;
}
else if($linha_cod_virtua['codBaixa'] == $todos_codigos[3])
{
$dado3 = $cont04++;
}
}
$totalCod = array($dado,$dado1,$dado2,$dado3);
rsort($totalCod);
Your question is very confusing. There are ways to add to it the structure of your table in the database and examples of what these records would look like?
– Woss
Can’t you provide the database structure + a mass of data? I needed to understand your database (what this data is) in order to understand the PHP code. I didn’t understand where the value of
$todos_codigos
– Fábio Jânio
WHERE codBaixa and
doesn’t make sense. And you can probably count and sort only in SQL.– bfavaretto