I can’t seem to get this working… And I can’t figure out why. Anyone?
The following code works just fine.
[php]
$list_of_sites = $db_connection->prepare(‘SELECT * from site_list WHERE approved=1 ORDER BY votes_up DESC, votes_down ASC’);
$list_of_sites->execute();
while ($row = $list_of_sites->fetch(PDO::FETCH_ASSOC)){
echo $row[‘site_url’];
}
[/php]
I’m attempting to paginate the results via the following code (which does not work)
[php]
$list_of_sites = $db_connection->prepare(‘SELECT * from site_list WHERE approved=1 ORDER BY votes_up DESC, votes_down ASC LIMIT ?,?’);
$list_of_sites->bindParam(1,$page_num);
$list_of_sites->bindParam(2,$paginate);
$list_of_sites->execute();
[/php]
This does not work either:
[php]
$list_of_sites = $db_connection->prepare(‘SELECT * from site_list WHERE approved=1 ORDER BY votes_up DESC, votes_down ASC LIMIT :page_num,:paginate’);
$list_of_sites->bindParam(’:page_num’,$page_num);
$list_of_sites->bindParam(’:paginate’,$paginate);
$list_of_sites->execute();
[/php]
yet this works just fine:
[php]
$list_of_sites = $db_connection->prepare(‘SELECT * from site_list WHERE approved=1 ORDER BY votes_up DESC, votes_down ASC LIMIT 1,10’);
$list_of_sites->execute();
[/php]
This code is used for output in all the above examples. What am I doing wrong?
[php]
while ($row = $list_of_sites->fetch(PDO::FETCH_ASSOC)){
echo $row[‘site_url’];
}
[/php]
The values of $page_num and $paginate have been checked with the echo statment and are verified to be 1 & 10.