Author
Message
snype Regular Joined: Aug 12, 2008 Posts: 58
Posted:
Tue Jun 01, 2010 7:49 am
Hello i wonder if some one could advise me on how i could add pagination to this module?
the code for the index.php is
Code: <?php
if (!defined('MODULE_FILE')) {
die('You can\'t access this file directly...');
}
require_once("mainfile.php");
$module_name = basename(dirname(__FILE__));
$index = 0;
include("header.php");
global $db, $prefix, $bgcolor1, $bgcolor3, $bgcolor2, $textcolor1, $module_name;
OpenTable();
echo "<center>\n<table width='100%' cellpadding='2' cellspacing='1' bgcolor='$bgcolor2'>\n";
echo "<tr><td align='center' colspan='4' class='option'><b><font color='gray'>Screencasts</font></b></td></tr>\n";
$result = $db->sql_query("SELECT * from ".$prefix."_screencasts ORDER BY pos ASC");
while($row = $db->sql_fetchrow($result)) {
$rid = intval($row['rid']);
$pos = intval($row['pos']);
$rtitle = $row['rtitle'];
$rimg = $row['rimg'];
$rurl = $row['rurl'];
$furl = $row['furl'];
$rdetails = $row['rdetails'];
$one = $row['one'];
echo "<tr bgcolor='$bgcolor1' align='center'>\n";
echo "<td align='left' colspan='2'><a href='$rurl' class='colorbox'><b>$rtitle</b></a></td><td align='right'><b>Screencast Image</b></td></tr>\n";
echo "<tr bgcolor='$bgcolor1'><td width='100%' colspan='2'>$rdetails<br/><br/><b>Duration</b> $one<br/><br/><a href='$furl'><b>Disscusions Forums</b></a></td>";
echo "<td align='right'><a href='$rurl' class='colorbox'><img src='$rimg' width='150' height='150' /></a></td></tr> ";
echo "<tr><td colspan='2'></td></tr>";
}
echo "</tr></table><br />";
CloseTable();
include("footer.php");
?>
Snype
Palbin Site Admin Joined: Mar 30, 2006 Posts: 2456 Location: Pittsburgh, Pennsylvania
Posted:
Tue Jun 01, 2010 5:08 pm
I didn't actually test this as I did not have database info, but it should get you very close.
Code:
<?php
if (!defined('MODULE_FILE')) {
Header('Location: index.php');
exit('Access Denied');
}
//Number of items per page
$perpage = 10;
if (isset($_GET['pagenum'])) {
$pagenum = abs(intval($_GET['pagenum']));
$min = $perpage * ($pagenum - 1);
$max = $min + $perpage;
} else {
$min = 0;
$max = $perpage;
}
require_once 'mainfile.php';
$module_name = basename(dirname(__FILE__));
$index = 0;
if (!defined('INDEX_FILE')) define('INDEX_FILE', false); // Set to FALSE to hide right blocks
if (defined('INDEX_FILE') AND INDEX_FILE === true) {
// auto set right blocks for pre patch 3.1 compatibility
$index = 1;
}
global $db, $prefix, $bgcolor1, $bgcolor3, $bgcolor2, $textcolor1, $module_name;
$result = $db->sql_query('SELECT * FROM `' . $prefix . '_screencasts` ORDER BY pos ASC');
$totalcasts = $db->sql_numrows($result);
$link = 'modules.php?name=' . $module_name;
$sPaginatorHTML = pagenums($link, $totalcasts, $perpage, $max);
include 'header.php';
OpenTable();
if ($sPaginatorHTML) {
echo $sPaginatorHTML;
}
echo '<center>' , "\n" , '<table width="100%" cellpadding="2" cellspacing="1" bgcolor="' , $bgcolor2 , '">' , "\n"
, '<tr><td align="center" colspan="4" class="option"><b><font color="gray">Screencasts</font></b></td></tr>' , "\n";
$result = $db->sql_query('SELECT * FROM `' . $prefix . '_screencasts` ORDER BY pos ASC');
while($row = $db->sql_fetchrow($result, MYSQL_ASSOC)) {
$rid = intval($row['rid']);
$pos = intval($row['pos']);
$rtitle = $row['rtitle'];
$rimg = $row['rimg'];
$rurl = $row['rurl'];
$furl = $row['furl'];
$rdetails = $row['rdetails'];
$one = $row['one'];
echo '<tr bgcolor="' , $bgcolor1 , '" align="center">' , "\n"
, '<td align="left" colspan="2"><a href="' , $rurl , '" class="colorbox"><b>' , $rtitle , '</b></a></td><td align="right"><b>Screencast Image</b></td></tr>' , "\n"
, '<tr bgcolor="' , $bgcolor1 , '"><td width="100%" colspan="2">' , $rdetails , '<br /><br /><b>Duration</b> ' , $one , '<br /><br /><a href="' , $furl , '"><b>Disscusions Forums</b></a></td>'
, '<td align="right"><a href="' , $rurl , '" class="colorbox"><img src="' , $rimg , '" width="150" height="150" /></a></td></tr>'
, '<tr><td colspan="2"></td></tr>';
}
echo '</tr></table><br />';
CloseTable();
include 'footer.php';
function pagenums($link, $totalselected, $perpage, $max) {
global $pagenum, $cfgPaginatorControl;
$pagenum = abs(intval($pagenum));
$usePaginatorControl = true;
$rowsperpage = $perpage + 1;
if ($totalselected < $rowsperpage) {
$usePaginatorControl = false;
}
if ($usePaginatorControl) {
include_once NUKE_CLASSES_DIR . 'class.paginator.php';
include_once NUKE_CLASSES_DIR . 'class.paginator_html.php';
$oPaginator = new Paginator_html($pagenum, $totalselected, $perpage);
$oPaginator->setDefaults($cfgPaginatorControl);
$oPaginator->set_Limit($perpage);
$oPaginator->set_Links($cfgPaginatorControl['iMaxPages']);
$oPaginator->setLink($link);
$oPaginator->setTotalItems(_PAGINATOR_TOTALSTORIES);
$sPaginatorHTML = $oPaginator->getPagerHTML() . '<br />';
return $sPaginatorHTML;
} else {
return false;
}
}
?>
snype Regular Joined: Aug 12, 2008 Posts: 58
Posted:
Tue Jun 01, 2010 7:22 pm
Palbin Many thanks for the help. And i have sent you a PM
Snype
View next topic
View previous topic
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum