count repeated fields of a column

-1

As I could count the repeated fields in my table, I tried that way more did not work:

Holds the name of the genres

    $generos = mysqli_query($conn,"SELECT * FROM 'generos'");

    while($res = mysqli_fetch_assoc($generos)){

            $nomeGenero             = $res['nome_genero'];
            $nomeGeneroCaracteres   = $res['nome_genero'];

            $gn = [rtrim(''.$nomeGenero.'',',')];

            foreach ($gn as $epAtual){

                @$generoAtual = $urlE[1];

                $contaGeneros = mysqli_query($conn,"SELECT * FROM 'seriados'");

                while($row = mysqli_fetch_assoc($contaGeneros)){

                    $genero = $row['genero_serie'];

                    $conta = mysqli_num_rows($genero);

                    if($generoAtual == $epAtual){

                        $epAtual = preg_replace('/[-]/ui', ' ',$epAtual);

                            echo '<li><a href="javascript:void(0)" class="ativo">'.utf8_encode($nomeGenero).' <strong>123</strong></a></li>'.PHP_EOL;

                    }else{

                            echo '<li><a href="'.$urlBase.'/genero/'.$nomeGeneroCaracteres.'">'.utf8_encode($nomeGenero).' <strong>123</strong></a></li>'.PHP_EOL;
                    }
            }
    }
}

Goal is to leave this: animes 2 | aventura 5 | comedia 7 .....

solution

I got it the following way, it's there for whoever needs it

$generos = mysqli_query($conn,"SELECT * FROM 'generos'");

while($res = mysqli_fetch_assoc($generos)){

    $nomeGenero             = $res['nome_genero'];
    $nomeGeneroCaracteres   = $res['nome_genero'];

    $generoSerie = $res['nome_genero'];

    $seriadosConta = mysqli_query($conn,"SELECT COUNT(genero_serie) AS TOTAL FROM seriados WHERE genero_serie LIKE '%$generoSerie%'");

    while($row = mysqli_fetch_assoc($seriadosConta)){

        $gn = [rtrim(''.$nomeGenero.'',',')];

        foreach ($gn as $epAtual){

        @$generoAtual = $urlE[1];
        if($generoAtual == $epAtual){

        $epAtual = preg_replace('/[-]/ui', ' ',$epAtual);

            echo '<li><a href="javascript:void(0)" class="ativo">'.utf8_encode($nomeGenero).' <strong>'.$row['TOTAL'].'</strong></a></li>'.PHP_EOL;

        }else{
            echo '<li><a href="'.$urlBase.'/genero/'.$nomeGeneroCaracteres.'">'.utf8_encode($nomeGenero).' <strong>'.$row['TOTAL'].'</strong></a></li>'.PHP_EOL;
        }
   }

} }

  

Source

using -mysqli to count records

    
asked by anonymous 13.08.2018 / 18:34

2 answers

1

Hello @Mayron, I'll put an example to see how you can check the repeated values:

<?php

$valores = array(1, 2, 2, 3, 3, 3, 4, 4, 4, 4);
$contagem = array_count_values($valores);

foreach($contagem AS $numero => $vezes) {

    /*aqui no if, vc pode definir qual o valor que deseja realizar a contagem dos repetidos*/
    if($vezes == 4) {
        echo "$numero - $vezes<br />";
    }

}

?>
    
13.08.2018 / 18:39
1

Follow the query just to count your total genres.

SELECT distinct(nome_genero), count(nome_genero) FROM generos group by nome_genero;
    
13.08.2018 / 19:21