2
require 'conn.php';
$cardPerRow = isset($_GET['rpp']) ? $_GET['rpp'] : 9;
$page = isset($_GET['page']) ? $_GET['page'] : 1;
$offset = $cardPerRow * ($page-1);
var_dump($offset);var_dump($cardPerRow);
        $query = "SELECT * FROM dbname.prodotti LIMIT ? OFFSET ?;";
        $stmt = $conn->prepare($query);
        //$stmt->bindParam(':offset',$offset);
        //$stmt-> bindParam(':cardPerRow',$cardPerRow);
        $stmt ->execute([$cardPerRow,$offset]);
        $data = $stmt ->fetchAll();
        echo json_encode($data);

This code return an empty array, but if i run the query on my database it returns my data. I really don't know why, for me everything is good. Is there something that i don't see? Thanks in advance.

coderz
  • 72
  • 6

1 Answers1

0

You cannot use bind parameters for the numbers in LIMIT and OFFSET clauses. You must embed those numbers directly in the text of your query.

And, if you had checked for errors that would have been clear. Please read this. Turning query errors to Exceptions in MySQLi

O. Jones
  • 103,626
  • 17
  • 118
  • 172