Notice: Object of class Pdostatement could not be converted to int in

Asked

Viewed 574 times

0

I do not understand much of the PHP part and I have a little problem that I am not able to solve.

WEBSITE ERROR

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

Code referring to line that is giving error I left marked 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

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.

  • My, my, my, I didn’t really notice that part.

  • Thank you very much, it helped a lot !!!

  • Quite normal, especially at the beginning. That’s how you learn. Good luck on this walk.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.