View Full Version : Virtual Pagination with Mysql??
jnscollier
03-25-2007, 05:02 PM
1) Script Title:
Virtual Pagination Script
2) Script URL (on DD):
http://www.dynamicdrive.com/dynamicindex17/virtualpagination.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. :eek:
thetestingsite
03-25-2007, 05:08 PM
Try something like this:
<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.
jnscollier
03-25-2007, 06:01 PM
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?
thetestingsite
03-25-2007, 06:18 PM
ok, try this:
<?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.
jnscollier
03-25-2007, 07:16 PM
<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 !!!!!!!!!!!!!!!!!!!!!!
thetestingsite
03-25-2007, 07:20 PM
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:
<?php
echo '</div>';
}
}
?>
to this:
<?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.
jnscollier
03-26-2007, 02:12 AM
Worked GREAT.... thanks for everything testingsite, it was displaying an extra page though, all i had to do was remove the ceil
thetestingsite
03-26-2007, 02:30 AM
ok...thanks, I will note it for next time. Glad to hear it is working for you.
acctman
11-09-2008, 10:21 PM
how would i apply the mysql and php code to this script http://www.dynamicdrive.com/dynamicindex17/ajaxpaginate/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.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.