Results 1 to 9 of 9

Thread: Virtual Pagination with Mysql??

  1. #1
    Join Date
    Jan 2007
    Posts
    94
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Cool Virtual Pagination with Mysql??

    1) Script Title:
    Virtual Pagination Script

    2) Script URL (on DD):
    http://www.dynamicdrive.com/dynamici...pagination.htm


    3) Describe problem:
    I love this script and in essence it would do exactly what I want, except... here's what I'm trying to do....

    I want to display comments on the bottom of my page and the comments are being pulled from a mysql table. I'd like users to be able to flip through the comments (next, prev, page numbers) without the top of the page reloading. I have tried regular pagination and it reloads the whole page, I don't want that. I just want the bottom of the page to change with the new content... Can someone please help???? I'm using php.

    Please let me know if I need to provide more clarification. ANY help would be GREATLY appreciated because I'm going insane.

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Try something like this:

    PHP Code:

    <div style="width: 400px; height: 250px">

    <?php
    include('dbconnect.php'); //this will have you connection details.

    $comments mysql_query("SELECT * FROM `comments`");

    while (
    $q mysql_fetch_array($comments)) {
    ?>  

    <div class="virtualpage">

    <?php echo $q['comments'];?>

    </div>

    <?php
    }
    ?>

    </div>
    This is just an example of what how you could do this. Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. #3
    Join Date
    Jan 2007
    Posts
    94
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Yeah, I got it this far, it shows every single comment on a separate page though, how can I make it so it shows first 15 comments on page 1, page 2 has comments 16-30, etc?

  4. #4
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    ok, try this:

    Code:
    <?php
    include('dbconnect.php'); //this will have you connection details.
    
    $pp = "15"; //total comments per page
    
    $total_comments = mysql_query("SELECT * FROM `comments`");
    $total =mysql_num_rows($total_comments);
    
    $total_pages = floor($total/$pp);
    
    for ($i=0; $i<=$total_pages; $i++) {
     $start = $pp * $i;
    
    $comments = mysql_query("SELECT * FROM `comments` LIMIT $start, $pp");
    
    echo '<div class="virtualpage">';
    
      while ($q = mysql_fetch_array($comments)) {
    ?>  
    
    <div><?php echo $q['comments'];?></div>
    
    <?php
    
    echo '</div>';
      }
    }
    ?>
    Not tested with the mysql aspect, but should work.

    Hope this helps.
    Last edited by thetestingsite; 04-20-2007 at 01:23 AM.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  5. #5
    Join Date
    Jan 2007
    Posts
    94
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Cool

    Code:
    <div style="width: 400px; height: 700px;">
    <?php
    include('dbconnect.php'); //this will have you connection details.
    
    $pp = "15"; //total comments per page
    
    $total_comments = mysql_query("SELECT * FROM ".COMMENTS."");
    $total =mysql_num_rows($total_comments);
    
    $total_pages = ceil($total/$pp);
    
    for ($i=0; $i<=$total_pages; $i++) {
     $start = $pp * $i;
    
    $comments = mysql_query("SELECT * FROM ".COMMENTS." LIMIT $start, $pp");
    
    echo '<div class="virtualpage">';
    
      while ($q = mysql_fetch_array($comments)) {
      
      
    $test = $q['comment'];
    ?>  
    
    <div><?php echo $test;?></div>
    
    <?php
    
    echo '</div>';
      }
    }
    ?>
    
    </div>
    
    
    <!-- Pagination DIV for Demo 1 -->
    <div id="gallerypaginate" class="paginationstyle">
    <a href="#" rel="previous">Prev</a> <span class="flatview"></span> <a href="#" rel="next">Next</a>
    </div>
    
    <!-- Initialize Demo 1 -->
    <script type="text/javascript">
    var gallery=new virtualpaginate("virtualpage", 1)
    gallery.buildpagination("gallerypaginate")
    </script>
    It just displays all 27 comments on the first page.... second page and third page... I'm at a complete loss. Thank you for the help testingsite... i don't know what else to do !!!!!!!!!!!!!!!!!!!!!!

  6. #6
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Can you post a link to the problem page, I think I see what the problem is in the code, but I just want to make sure. Either way, try changing this part:

    Code:
    <?php
    
    echo '</div>';
      }
    }
    ?>
    to this:

    Code:
    <?php
      }
    
    echo '</div>';
    
    }
    ?>
    Notice how the closing div is below the first closing bracket. Try that, and if that still doesn't work, post (or PM) the link, and I'll take a look at it.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  7. #7
    Join Date
    Jan 2007
    Posts
    94
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Worked GREAT.... thanks for everything testingsite, it was displaying an extra page though, all i had to do was remove the ceil

  8. #8
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    ok...thanks, I will note it for next time. Glad to hear it is working for you.
    Last edited by thetestingsite; 03-26-2007 at 02:31 PM.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  9. #9
    Join Date
    Jul 2006
    Posts
    64
    Thanks
    22
    Thanked 0 Times in 0 Posts

    Default

    how would i apply the mysql and php code to this script http://www.dynamicdrive.com/dynamici...nate/index.htm ?

    I currently have a page that displays over 100 user images with user names next to them from a mysql php query code. I would love to be able to setup a pagination that would allow me to display 20 at a time from the query.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •