Struggling to Paginate with PHP MSSQL PDO
I'm using MSSQL, so I think the problem is having the LIMIT 10,20 clause in the query, but looking at the alternative ways to do this with MSSQL rather than MySQL look really complicated.
If somebody could take a look at this script and let me know where I'm going wrong, that would be great.
<?php
$sth = $dbconn->prepare ("SELECT publication.id, publication.title, publication.text, publication.country, publication.city, publication.cat, publication.user_id, publication.use_ad, publication.viewcount,
publication.tags, publication.status, publication.mod_status, publication_issue.publication_id, publication_issue.img, publication_issue.id AS Expr1
FROM publication INNER JOIN
publication_issue ON publication.id = publication_issue.publication_id
WHERE (publication.tags LIKE :tags)");
$results = $sth->execute(array(":tags"=>'%e%'));
while ($row = $sth->fetchAll(PDO::FETCH_ASSOC)) {
echo "id: ".$row['id'];
$pages = ceil(count($row)/4);
$page = (isset ($_GET['page'])) ? (int) $_GET['page'] : 1 ;
$start = ($page - 1) * $per_page;
// $data = $row[0] . "\t" . $row[1] . "\t" . $row[2] . "\n";
echo '<br>' . $results[0] . '<br>' . $row['title'] . '<br>' . $row['img'] . '<br>';
?>
<br><br>
<?php
if ($pages >= 1 && $page <= $pages){
//if ($page>1 && $page <= $pages){$previous=($page -1); echo '<a href="?page=' .$previous. '">Previous</a>';}
for($x=1; $x<=$pages; $x++){ echo ($x == $page) ? ' <strong><a href="?page='.$x.'">'.$x.'</a></strong> ' : ' <a href="?page='.$x.'">'.$x.'</a> ';}
//if ($page>1 && $page <= $pages){ $next=($page+1) ; echo '<a href="?page=' .$next. '">Next</a>';}
}
}
?>
-
Brendanm -
Thanks
SignatureFree Mp3 Downloads{{ DiscussionBoard.errors[8040656].message }} -
-
vick2011 -
Thanks
{{ DiscussionBoard.errors[8040981].message }} -