Possible duplicate:
PHP PDO bindValue in LIMIT
This code works for me very well.
if (array_key_exists('cat', $_GET) === TRUE) { $category = $_GET['cat']; } else { $category = '.*'; } $conn = new PDO('mysql:host=localhost;dbname=news', 'root', ''); $stmt = $conn->prepare('SELECT * FROM stories WHERE category RLIKE :cat ORDER BY score DESC LIMIT 0, 25'); $stmt -> execute(array( 'cat' => $category, )); $result = $stmt->fetchAll();
As you can see, he gets the category from the request for receipt and looks for a database for everything in this category.
I am also trying to add a bit so that the page can be specified in the get request and the request will start 25 lines later for each increment by one on the page.
Here is what I wrote:
if (array_key_exists('cat', $_GET) === TRUE) { $category = $_GET['cat']; } else { $category = '.*'; } if (array_key_exists('page', $_GET) === TRUE) { $page = intval($_GET['page'])*25; } else { $page = 0; } $conn = new PDO('mysql:host=localhost;dbname=news', 'root', ''); $stmt = $conn->prepare('SELECT * FROM stories WHERE category RLIKE :cat ORDER BY score DESC LIMIT :page, 25'); $stmt -> execute(array( 'cat' => $category, 'page' => $page )); $result = $stmt->fetchAll();
But now the query returns nothing, regardless of which page or if there is a category.
Perhaps I am not entitled to integers. Any idea why I get this result?
source share