View Full Version : need help with placing SQL code in Pagination script

01-29-2010, 12:11 AM
I found a REALLY good pagination script at this link.. http://www.dynamicdrive.com/dynamicindex17/ajaxpaginate/index.htm.

The problem is that I cant get it to work with my DB correctly. He explains how to do it but the guy is not a very good teacher and I cant get it to work.

I want it do go into the DB, select 5 records and loop through each one and display it with a bunch of formatting.

Here is an abbreviated version of the code I want to place in the pag. script: // prepare SQL to retrieve subset of image details
$query1 = "SELECT * FROM video WHERE video_username = '$username' ORDER BY video_upload_date DESC
mysql_select_db($database_db294582132, $db294582132);
$result1 = mysql_query($query1, $db294582132) or die(mysql_error());

while($row1 = mysql_fetch_assoc($result1)){
****define some variables from table 1******
//get vehicle info according to ID in query1
$query2 = "SELECT * FROM user_vehicles WHERE vehicle_id = '$vehicle_id'";
mysql_select_db($database_db294582132, $db294582132);
$result2 = mysql_query($query2, $db294582132) or die(mysql_error());
****define more variables from table 2****
//Get setup info
$query4 = "SELECT * FROM vehicle_setups WHERE setup_id = '$video_setup'";
mysql_select_db($database_db294582132, $db294582132);
$result4 = mysql_query($query4, $db294582132) or die(mysql_error());
$row4 = mysql_fetch_assoc($result4);
$setup = $row4['setup'];
//provide format for uploaded videos section
'****bunch of HTML and $variables*****';The part the the instructor puts the dynamic code in is in here: taken straight from the tutorial
<script type="text/javascript">


echo "var commentsbook={\n"; //Dynamically output javascript variable
$commentids=mysql_query("select id from comments order by date limit 5"); //get IDs to last 5 comment pages
while ($theid=mysql_fetch_array($commentids)){
array_push($idarray, "'http://www.mysite.com/comments.php?id=" . $theid[id] . "'");
echo "pages: [" . implode(",", $idarray) . "],\n"; //output: pages: [filepath1, filepath2, filepath3, etc],
echo "selectedpage: 0\n}";


var comments=new ajaxpageclass.createBook(commentsbook, "bookdiv", ["paginate-top", "paginate-bottom"])


so, How do I put my code into the second part and make it work??? im rackin my brain. thanks

01-29-2010, 12:27 AM
unless im missing something the script you mention is a ajax/javascript solution where the linked pages are hardcoded. you are trying to paginate using php. why not use a php pagination script?

02-04-2010, 04:04 AM
im trying to use ajax b/c then I can do it without refreshing the page, it would be really useful to be used in spry tabbed pages