venu A

venu A

  • NA
  • 5
  • 18.5k

How to virtually paginate tabbed php page

Sep 27 2009 4:00 PM
I wrote this script to make a blogging site but the virtual pagination appears on every tab. How do I create virtual pagination for individual tabs. I wrote a code but
Here is the code
 <?php
//  database connection
require_once('./includes/base.php');
if($_GET['logout'] == 1){
    @$_SESSION = array();
    @session_unregister($_SESSION['userID']);
    @session_unregister($_SESSION['userName']);
    @session_unregister($_SESSION['userUser']);
    @session_unregister($_SESSION['userPass']);
    @session_destroy();
}
require("./templates/$template/header.php");
include 'pagination.class.php';
?>
<div id="blurb"  align="right">
<script language="javascript">
    function isClear()
        {
            document.myForm[0].value='';
            return true;
       
        }
    </script>
    <!-- new search -->
    <?php
ob_start();
if(!empty($_SESSION['userID']) and !empty($_POST['user'])){
echo '<form action="search.php" method="post" name="myForm">
<input type="text" value="search here" id="search" size="20" name="search" onFocus="return isClear();"/>
<input type="submit" name="serachuser" value="search"/></form>';
}
?>
</div>
<br>
<div id="blurb" align="justify">
Hello world <?php echo "$sitename"; ?> is blah, blah, blah.......!
</div>
<br>
 <div id="container-5">
            <ul>
                <li><a href="#fragment-13"><span>Blogs</span></a></li>
                <li><a href="#fragment-14"><span>Links</span></a></li>
                <li><a href="#fragment-15"><span>Images</span></a></li>
            </ul>
            <div id="fragment-13">
                <?php
   
$sql = mysql_query("SELECT users.userUser, posts.postID, posts.postPost, posts.postTime, posts.postComments, userAvatar  FROM users, posts WHERE users.userID = posts.postUserID ORDER BY posts.postTime DESC ");                 
while($row = mysql_fetch_array($sql)){
    $abcd= $row['userName'];
    $abcd = str_replace (" ", "-", $abcd);
 $time = reltime($row['postTime']);
    echo '
    <div class="virtualpage">
     <table width="100%" >
      <td width="10%" ><a href="'.$site_url.'/'.$row['userUser'].'"><img src="'.$site_url.'/avatars/'.$row['userAvatar'].'"  width="48px" height="48px" /><td width="90% "bgcolor="#F8F8F8"  border=1" cellspacing="1" cellpadding="1" ><b>'.$row['postPost'].'</b><br>Posted by:&nbsp;'.$row['userUser'].',&nbsp;<a href="'.$site_url.'/blogs/'.$row['userUser'].'/'.$row['postID'].'">Comments</a>&nbsp;'.$row['postComments'].' ,&nbsp;Time elapsed:&nbsp; '.$time.'</a></td>
    </table><br>
   
    </div>';}
 

    ?>
<div id="gallerypaginate" class="paginationstyle">
<a href="#" rel="previous">Prev</a> <span class="flatview"></span> <a href="#" rel="next">Next</a>
</div>
<table align="center"><tr><td align="center">
<script type="text/javascript"  defer="defer">
var gallery=new virtualpaginate("virtualpage",10)
gallery.buildpagination("gallerypaginate")
</script>
</td></tr></table>
            </div>

</div>
 
            </div>

            <div id="fragment-14">
                <?php
                 $sql = mysql_query("SELECT users.userUser, links.linksID, links.linksLink, links.linksPost, links.linksTime, links.linksComments,userAvatar FROM users, links WHERE users.userID = links.linksUserID ORDER BY links.linksTime DESC");
while($row = mysql_fetch_array($sql)){
    $abcd= $row['userName'];
    $abcd = str_replace (" ", "-", $abcd);
 $time1 = reltime($row['linksTime']);
    echo '
    <div class="virtualpage">
     <table width="100%" >
      <td width="10%" ><a href="'.$site_url.'/'.$row['userUser'].'"><img src="'.$site_url.'/avatars/'.$row['userAvatar'].'"  width="48px" height="48px" /><td width="90% "bgcolor="#F8F8F8"  border=1" cellspacing="1" cellpadding="1" ><b>'.$row['linksPost'].'</b><br>Posted by:&nbsp;'.$row['userUser'].',&nbsp;<a href="'.$site_url.'/blogs/'.$row['userUser'].'/'.$row['linksID'].'">Comments</a>&nbsp;'.$row['linksComments'].' ,&nbsp;Time elapsed:&nbsp; '.$time1.'</a></td>
    </table><br>
   
    </div>';}
    ?>

 

            </div>
            <div id="fragment-15">
                <?php
                // testing
                grabimages('SELECT users.userUser, images.imagesID, images.imagesFile, images.imagesPost, images.imagesTime, images.imagesComments FROM users, images WHERE users.userID = images.imagesUserID ORDER BY images.imagesTime DESC LIMIT 20');
                ?>
            </div>
        </div>
 
 
 

<?php
// Display footer
require("./templates/$template/footer.php");
?>
 
 

here is the pagination.class.php
 <?php
  /************************************************************\
  *
  *   PHP Array Pagination Copyright 2007 - Derek Harvey
  *   www.lotsofcode.com
  *
  *   This file is part of PHP Array Pagination .
  *
  *   PHP Array Pagination is free software; you can redistribute it and/or modify
  *   it under the terms of the GNU General Public License as published by
  *   the Free Software Foundation; either version 2 of the License, or
  *   (at your option) any later version.
  *
  *   PHP Array Pagination is distributed in the hope that it will be useful,
  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  *   GNU General Public License for more details.
  *
  *   You should have received a copy of the GNU General Public License
  *   along with PHP Array Pagination ; if not, write to the Free Software
  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
  \************************************************************/
  class pagination
  {
    var $page = 1; // Current Page
    var $perPage = 10; // Items on each page, defaulted to 10
    var $showFirstAndLast = false; // if you would like the first and last page options.
   
    function generate($array, $perPage = 10)
    {
      // Assign the items per page variable
      if (!empty($perPage))
        $this->perPage = $perPage;
     
      // Assign the page variable
      if (!empty($_GET['page'])) {
        $this->page = $_GET['page']; // using the get method
      } else {
        $this->page = 1; // if we don't have a page number then assume we are on the first page
      }
     
      // Take the length of the array
      $this->length = count($array);
     
      // Get the number of pages
      $this->pages = ceil($this->length / $this->perPage);
     
      // Calculate the starting point
      $this->start  = ceil(($this->page - 1) * $this->perPage);
     
      // Return the part of the array we have requested
      return array_slice($array, $this->start, $this->perPage);
    }
   
    function links()
    {
      // Initiate the links array
      $plinks = array();
      $links = array();
      $slinks = array();
     
      // Concatenate the get variables to add to the page numbering string
      if (count($_GET)) {
        $queryURL = '';
        foreach ($_GET as $key => $value) {
          if ($key != 'page') {
            $queryURL .= '&'.$key.'='.$value;
          }
        }
      }
     
      // If we have more then one pages
      if (($this->pages) > 1)
      {
        // Assign the 'previous page' link into the array if we are not on the first page
        if ($this->page != 1) {
          if ($this->showFirstAndLast) {
            $plinks[] = ' <a href="?page=1'.$queryURL.'">&laquo;&laquo; First </a> ';
          }
          $plinks[] = ' <a href="?page='.($this->page - 1).$queryURL.'">&laquo; Prev</a> ';
        }
       
        // Assign all the page numbers & links to the array
        for ($j = 1; $j < ($this->pages + 1); $j++) {
          if ($this->page == $j) {
            $links[] = ' <a class="selected">'.$j.'</a> '; // If we are on the same page as the current item
          } else {
            $links[] = ' <a href="?page='.$j.$queryURL.'">'.$j.'</a> '; // add the link to the array
          }
        }
 
        // Assign the 'next page' if we are not on the last page
        if ($this->page < $this->pages) {
          $slinks[] = ' <a href="?page='.($this->page + 1).$queryURL.'"> Next &raquo; </a> ';
          if ($this->showFirstAndLast) {
            $slinks[] = ' <a href="?page='.($this->pages).$queryURL.'"> Last &raquo;&raquo; </a> ';
          }
        }
       
        // Push the array into a string using any some glue
        return implode(' ', $plinks).implode($this->implodeBy, $links).implode(' ', $slinks);
      }
      return;
    }
  }
?>

The object is to create pagination for fragment-13, fragment-14 and fragment-15 separately without conflict.

I am a self taught programmer. So, please reply with corrected code. Thanks.

Answers (1)