Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> Converting/Creating Modules
Author Message
snype
Regular
Regular



Joined: Aug 12, 2008
Posts: 58

PostPosted: Tue Jun 01, 2010 7:49 am Reply with quote

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>&nbsp;$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

_________________
visit [ Only registered users can see links on this board! Get registered or login! ] for all your CMS installs today 
View user's profile Send private message
Palbin
Site Admin



Joined: Mar 30, 2006
Posts: 2583
Location: Pittsburgh, Pennsylvania

PostPosted: Tue Jun 01, 2010 5:08 pm Reply with quote

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>&nbsp;' , $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;
   }
}

?>

_________________
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan. 
View user's profile Send private message
snype







PostPosted: Tue Jun 01, 2010 7:22 pm Reply with quote

Palbin Many thanks for the help. And i have sent you a PM

Snype
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> Converting/Creating Modules

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
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©