Register Advertise with usHelp Desk Today's Posts Search

Closed Thread
Thread Tools Search this Thread
Unread 25th Apr 2013, 06:38 AM   #1
Warrior Member
 
Join Date: 2009
Posts: 22
Thanks: 0
Thanked 2 Times in 2 Posts
Default
Struggling to Paginate with PHP MSSQL PDO
Share on: 
fb share twitter share gplus share more share

I can output the pages with a list 1 | 2 | 3 | 4 pages but not the actual data.

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 Code:
<?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>';}
    
}


}



?>
scottlpool2003 is offline  
Unread 3rd May 2013, 05:41 PM   #2
Active Warrior
 
Join Date: 2011
Posts: 81
Thanks: 8
Thanked 4 Times in 4 Posts
Default
Re: Struggling to Paginate with PHP MSSQL PDO
Share on: 
fb share twitter share gplus share more share

Check this tutorial on a basic pagination, i use this a lot.

Brendanm is offline  
Unread 3rd May 2013, 08:38 PM   #3
Junior Internet Marketer
War Room Member
 
Join Date: 2011
Location: Australia
Posts: 109
Thanks: 4
Thanked 11 Times in 6 Posts
Blog Entries: 7
Default
Re: Struggling to Paginate with PHP MSSQL PDO
Share on: 
fb share twitter share gplus share more share

Hi,

I suggest you stop using MySQL first and completely migrate to using simple SQL with PDO, Onlinesupport Q&A.
vick2011 is offline  
Closed Thread


Bookmarks

Tags
mssql, pagination, pdo, php


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -6. The time now is 12:25 PM.