Possible Duplicate:
PHP PDO bindValue in LIMIT
I have this code that works quite 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, it gets a category from the get request, and searches the database for everything in that category.
I'm also trying to add a bit so that there can be a page defined in the get request, and the query will start 25 rows later for each increase by one in page.
Here's 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 is returning nothing, no matter what page is, or if there is a category.
Maybe I'm not dealing with integers right. Any idea why I'm getting this result?