0

Im trying to devellop a pagination system and Im having an strange issue. I have this code below and the code is always entering in my if condition saying there are 0 results. But I have the sql statment correct when I do a print_r. Can you see if theres something wrong that I´m not seeing?

 $pag = (empty($_GET['pag']) ? '1' : $_GET['pag']);
            $max = 3;
            $begin = ($pag * $max) - $max;
            $readPages = $pdo->prepare("SELECT * FROM pages where id_numb IS null LIMIT :beg,:ma");  
            $readPages->bindValue(":beg", $begin);
            $readPages->bindValue(":ma", $max);    
            $readPages->execute();
            $num_rows = $readPages->rowCount();

            if(!$num_rows >= 1)
            {
                echo '0 results';
            }
OzzC
  • 815
  • 4
  • 20
  • 36

2 Answers2

1
  1. always enable exception mode for PDO to be notified of SQL errors
  2. for the LIMIT clause you have to set PDO::PARAM_INT explicitly
Community
  • 1
  • 1
Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
0
        $num_rows = readPages->rowCount();
                    ^---missing $. A constant object? no way...
        print_r($lerCat);
                 ^^^^^^--- undefined variable
Marc B
  • 356,200
  • 43
  • 426
  • 500