How do I paginate muti tabbed site

Discussion in 'Programming' started by Venu12, Sep 28, 2009.

  1. #1
     
    <?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");
    
    ?>
    
    <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>Chat, news and more</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>
    
    
                </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 id="gallerypaginate" class="paginationstyle">
    <a href="#" rel="previous">Prev</a> <span class="flatview"></span> <a href="#" rel="next">Next</a>
    </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");
    ?>
    
    <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>
    
    
    
    
    Code (markup):
    I am a self taught php programmer. So, please mention the corrected code. Thanks.
     
    Venu12, Sep 28, 2009 IP
  2. ohteddy

    ohteddy Member

    Messages:
    128
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    28
    #2
    To accomplish pagination you need to know:

    offset (default is 0)
    length (say 10)
    page_no (default 1)
    total_records (used to calculate number of pages)

    Once you have done the math to calculate the new offset and
    length based on the page selected, use "LIMIT offset, (offset+length)"
    in your SQL query to return only those results between the offset
    and length.
     
    ohteddy, Sep 28, 2009 IP
  3. Venu12

    Venu12 Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks for your suggestion. I am trying to accomplish virtual pagination(not the conventional pagination with $start $end at for the Limit in $sql) with the following code in ajax. I am a self taught programmer and Ajax is new to me. I am using the Ajax code by www.dynamicdrive.com
    
    [COLOR="SeaGreen"]<div id="gallerypaginate" class="paginationstyle">
    <a href="#" rel="previous">Prev</a> <span class="flatview"></span> <a href="#" rel="next">Next</a>
    </div>[/COLOR]
    Code (markup):
    I placed this code within <div id="fragment-13"> ...</div> with virtualpagination.js in the header.php and

    
    [COLOR="SeaGreen"]<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>[/COLOR]
    Code (markup):
    at the very bottom of the main page. It works well for fragment-13 even with DESC in the $sql query but this virtual pagination shows up in fraagment-14 and fragment-15 as well.

    I would like to hide the pagination for fragment-13 so that I could separately create virtual pagination for fragment-14 and 15.

    If I am not understanding what your suggestion is because of my self learning of codes, would you please modufu the virtual pagination Ajax script. Ajax is new to me. I am still trying to figure out how Ajax works.

    To summerize, I would like to use this Ajax script to work in <div id="fragment-13">...</div> <div id="fragment-14"> <div id="fragment-15"> separately by giving a class name <div class="virtualpage"> for
    
     echo '
     [COLOR="DarkOrange"]<div class="virtualpage">  [/COLOR] 
         <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>';
    
    Code (markup):
     
    Venu12, Sep 29, 2009 IP
  4. Venu12

    Venu12 Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    var gallery=new virtualpaginate("virtualpage",10) // which, I think, means the lenght is 10. I am sorry but I just started learning Ajax/Jquery a couple of days ago by myself. virtualpage is the name of the class. I guess, gallery.buildpagination("gallerypaginate") paginate the page virtually. By experimenting, I noticed that additonal buttons or numbers could be placed by modifying gallery.buildpagination("gallerypaginate") . What I am looking for is some variable to stop this pagination just for fragment-13; something like "persist: false' so that the pagination for fragment-13 will not appear in fragment-14 and 15. How do I do that?

    I guess the trick may be modifying this code
    
     <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>
    Code (markup):
     
    Venu12, Sep 29, 2009 IP
  5. Venu12

    Venu12 Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I fixed the problem all by myself. My site www.allmicrochat.com is now running with virtual pagination in each and every tab!

    Thanks anyway. Learned somenthing new as a self taught prgrammer.
     
    Venu12, Sep 30, 2009 IP