Using mysql_num_rows with PDO [closed]

-1

I changed the method of connecting my page to my Database via PDO. I used until then a paging code but it is now returning the error:

  

Warning: mysql_num_rows () expects parameter 1 to be resource, string given in D: \ xampp \ htdocs \ n_archaeus \ inc \ index.php on line 85

My code looks like this:

$pg = isset($_GET['pg'])?$_GET['pg']:"1";

$quantidade = 3;

$ini = ($pg*$quantidade) - $quantidade;

$qry = "
SELECT 
content.id_content, 
content.img, 
content.titulo, 
povos.pv, 
cat.categoria, 
content.inicio, 
content.fim, 
content.content, 
regiao.reg, 
regiao.wmap
FROM cat 
INNER JOIN regiao 
INNER JOIN povos 
INNER JOIN content ON povos.id_povos = content.civ 
AND regiao.id_regiao = povos.regiao 
AND cat.id_cat = content.clas
ORDER BY inicio 
LIMIT $ini, $quantidade";

    $resultado = $PDO->query( $qry );
    $rows = $resultado->fetchAll(PDO::FETCH_ASSOC);
    foreach ($rows as $key => $linha) {

        $civ = $linha['pv'];
        $clas = $linha['categoria'];
        $inicio = $linha['inicio'];
        $fim = $linha['fim'];
        $titulo = $linha['titulo'];
        $conteudo = $linha['content'];
        $imagem = $linha['img'];
        $reg = $linha['reg'];
        $wmap = $linha['wmap'];

        echo  $civ; etc. etc. etc...

       }

$sql_2 = "SELECT * FROM content ORDER BY inicio ";
    $res_2 = $PDO->query( $sql_2 );
    $row_2 = $res_2->fetchAll(PDO::FETCH_ASSOC);

$total_registros = mysql_num_rows($sql_2);

$paginas = ceil($total_registros/$quantidade);
$links = '9';

echo "<br><center><p class='paginas'><a href='?id=37&pg=1'>Primeira P&aacute;gina </a>&nbsp;&nbsp;";

for($i = $pg-$links; $i <= $pg-1; $i++){
        if($i<=0){
            }else{
                echo "&nbsp;&nbsp;<a href='?id=37&pg=".$i."'><strong>".$i."</strong></a>&nbsp;&nbsp;";
                }
    }

    echo "<a href=#> [ $pg ] </a>";

for($i = $pg+1; $i <= $pg+$links; $i++){
        if($i>$paginas){
            }else{
                echo "&nbsp;&nbsp;<a href='?id=37&pg=".$i."'>".$i."</a>&nbsp;&nbsp;";
                }
    }

echo "&nbsp;&nbsp;&nbsp;&nbsp;<a href='?id=37&pg=".$paginas."'>&Uacute;ltima P&aacute;gina </a></p></center>&nbsp;&nbsp;";
?>
    
asked by anonymous 09.08.2018 / 19:44

1 answer

1

It was necessary to call rowCount() of the Statement that is using the $res_2 variable. In this case it was called

$total_registros = $res_2->rowCount()

To have the total of records selected.

    
29.08.2018 / 20:54