PDA

View Full Version : Virtual Pagination with PHP5



CM Tech
08-08-2008, 07:00 PM
1) Script Title: Virtual Pagination

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex17/virtualpagination.htm

3) Describe problem: I am using the Virtual Pagination script with a PHP5 query statment. The problem that I am experiencing is that the pagination links always produce an additional blank page link at the end. i.e. <Prev 1234 Next> with pagination link 4 being a blank page.

Does anyone have any ideas. My query statement is below. Thnak you for your help.

$xajax->register(XAJAX_FUNCTION, 'dataInitiate');
function dataInitiate(){
$objResponse = new myXajaxResponse();
$pp = "10";
$total_kbs = mysql_query("SELECT * FROM ca_kb_master ORDER BY title");
$total =mysql_num_rows($total_kbs);
$rowcount = "<center>The Search Found <strong>".$total."</strong> Record(s)</center>";
$total_pages = ceil($total/$pp);
for ($i=0; $i<=$total_pages; $i++){
$start = $pp * $i;
$kbs = mysql_query("SELECT * FROM ca_kb_master ORDER BY title LIMIT $start, $pp");
$html .= "<div class='virtualpage'>";
while($row = mysql_fetch_array ($kbs))
{
$html .= "<div><br /><strong><a href='".$row['url']."' target='_blank' class='datatitlelink'>".$row['title']."</a></strong><br />".$row['description']."<br /><a href='".$row['url']."' target='_blank' alt='".$row['url']."' class='kblink'>".substr($row['url'], 0, 75)."</a><br /><a href='".$row['url']."' target='_blank' alt='".$row['url']."' class='kblink'>More...</a><br /><br /></div>";
}
$html .= "</div>";
}
$html .= "<div id='gallerypaginatebottom' class='paginationstyle'><a href='#' rel='previous' id='previous_page'><<&#160;&#160;Prev</a> <span class='flatview'></span><a href='#' rel='next' id='next_page'>Next&#160;&#160;>></a></div>";
$objResponse->assign("divRows","innerHTML",$rowcount);
$objResponse->assign("divDisplay","innerHTML",$html);
$objResponse->script("var gallery=new virtualpaginate('virtualpage', 1); gallery.buildpagination('gallerypaginatetop');");
return $objResponse;
}

ddadmin
08-09-2008, 06:59 AM
It's probably easier just to see the rendered page. Please post a link to the page on your site that contains the problematic script so we can check it out.

CM Tech
08-09-2008, 06:36 PM
ddadmin,
Thank you for responding. Unfortunately, the site is located inside an intranet. I'll work on getting a temporary external sample setup for you to review. I'll follow up shortly. Thank you again!
Dan

CM Tech
08-14-2008, 04:58 AM
ddadmin,

Thank you for the offer to review our intranet site. I was able to resolve the issue prior to getting the example on an external site for you. The issue was an unnecessary "=" character in my "for" statement. I hate it when that happens. The script works great and I am grateful for the hard work put into this forum and the developers script.

Below is a modified version of the script that I haev worked into an Xajax implementation. It works nicely and was not difficult to implement.

Thanks again,
Dan


Working and final Xajax version of the Virtual Pagination script:
$xajax->register(XAJAX_FUNCTION, 'dataInitiate');
function dataInitiate(){
$objResponse = new myXajaxResponse();
$rowsPerPage = "10";
$total_kbs = mysql_query("SELECT * FROM ca_kb_master");
$total = mysql_num_rows($total_kbs);
$total_pages = ceil($total/$rowsPerPage);
for($i=0;$i<$total_pages;$i++){
$start = $i * $rowsPerPage;
$kbs = mysql_query("SELECT * FROM ca_kb_master ORDER BY title LIMIT $start, $rowsPerPage");
$html .= "<div class='virtualpage'>";
while($row = mysql_fetch_array ($kbs))
{
$html .= "<br /><strong><a href='".$row['url']."' target='_blank' class='datatitlelink'>".$row['title']."</a></strong><br />".$row['description']."<br /><a href='".$row['url']."' target='_blank' alt='".$row['url']."' class='kblink'>".substr($row['url'], 0, 75)."</a><br /><a href='".$row['url']."' target='_blank' alt='".$row['url']."' class='kblink'>More...</a><br /><br />";
}
$html .= "</div>";
}
$html .= "<div id='gallerypaginate' class='paginationstyle'><a href='#' rel='previous' id='previous_page'><•&#160;&#160;Prev</a> <span class='flatview'></span><a href='#' rel='next' id='next_page'>Next&#160;&#160;•></a></div>";
$rowcount = "<center>The search found <strong>".$total."</strong> article(s) which are displayed on <strong>".$total_pages."</strong> pages below.</center>";
$objResponse->assign("divRows","innerHTML",$rowcount);
$objResponse->assign("divDisplay","innerHTML",$html);
$objResponse->script("var gallery=new virtualpaginate('virtualpage', 1); gallery.buildpagination('gallerypaginate');");
return $objResponse;
}