Notice: Object of class PDOStatement could not be converted to int

0

I do not understand much about PHP and I have a problem that I can not solve.

Site ERROR

Notice: Object of class PDOStatement could not be converted to int in orcamento.php on line 63

Code referring to the line that is giving error I left a mark where the line 63 is located

    <?php
                    $sql_sb = "SELECT * FROM tbl_album WHERE ALBUM_STATUS = 1 ORDER BY ALBUM_NOME ASC";
                    $b = $con->query($sql_sb);
                    $nRows = $con->query($sql_sb);
                    $i = 3;
                ?>
                    <table>

                <?php
                **linha 63 aqui**   if($nRows > 0){
                        while($busca = $b->fetch(PDO::FETCH_ASSOC)){
                            if($i % 3 == 0){
                                echo '<tr>';
                            }
                                echo '<td>';
                                echo '<li><input type="checkbox" value="'.$busca['ALBUM_NOME'].'">'.$busca['ALBUM_NOME'].'</li>';
                                echo '</td>';
                            //echo '</tr>';
                            $i++;
                        }
                    }else{
                        echo "Não há produtos cadastrados";
                    }
                ?>

Thank you

    
asked by anonymous 20.10.2016 / 21:06

1 answer

1

Hello. Make the following change:

$nRows = $con->query($sql_sb);

To

$nRows = $b->rowCount();

If you notice, $ nRows has the same value as $ b, so instead of retrieving the number of columns, you are re-executing the same query.

    
20.10.2016 / 21:26