Jump to content

Pagination Help!.


atlanta

Recommended Posts

Hey guys needed alittle help here on my script.

The scripts reads all graphics in a chosen folder and then it shows the page with Previous and Next page buttons . I couldnt successfully make it add numbers in between them like Prev 1 2 3 ... Next

etc..

 

here is the code thanks in advance...

Pagination output is near bottom of code

 

<?
require_once( ROOT_DIR ."/include/db.php");
$title = $desc = $pagename = "Graphics Gallery";
$layout = "content";

?>
<script type="text/JavaScript">
<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
//-->
</script>



    

<table width="100%">
  <tr>
    <td><div align="center"><h1>Browse Folders</h1>
<?

$urlpath = "$GPATH";
$cat = "$GROOT";

$max2show = 3; //Amount you want to show per page

$numFolderColumns = 1;	// Number of columns of folder names you want to show on each row 

// END OF CONFIGURATION SECTION
// Do not edit below this line

// Folder support
if(isset($_GET['folder']))
{
$cat .= $_GET['folder'] . '/';
$urlpath .= $_GET['folder'] . '/';
}

$hook = opendir($cat) or die('cant open dir');
$total = 0;

if(!isset($_GET['page'])) $page = 1;
else $page = $_GET['page'];

$start = $max2show * $page - $max2show;
$end = $page * $max2show;

/* folder support */
$directories = array();
/* End folder support part */

$ext = array("jpg", "png", "jpeg", "gif");
while (false!==($file = readdir($hook))) {
$idnum = "1";
// Functionality to check folders added here
$fpath = $cat . $file;

if(is_dir($fpath))
{
  //echo 
	if($file != '.' && $file != '..')
	{
		array_push($directories, $file);
	}
}
// folder support ends here

for($i=0;$i<sizeof($ext);$i++)
{
	if (stristr($file, ".".$ext[$i])) //NOT case sensitive 
	{
		$files[] = $file; 
		$total++;
	}
}
}
closedir($hook);
natcasesort($files);
$files = array_values($files);

/* Modification part to display folders */
if(count($directories) > 0)
{

  
$loopCounter = 1;
foreach($directories as $directory)
{


	echo ' <a href="' . $_SERVER['PHP_SELF'] . '?app=graphics-gallery&page=1&folder=' . urlencode($directory) . '"><b>' . $directory . '</b></a> ~';




	$loopCounter += 1;
}

;
}

if(!empty($_GET['folder']))
{
echo '</div><span>Viewing subfolder: <b>' . $_GET['folder'] . '</b></span><br /><a href="/graphics-gallery"><b>Back To Gallery Index</b></a><br />';
}
/* End modification part */

if ($end > $total) { $end = $total; }

echo '<table width="100%"  border="0" cellspacing="0" cellpadding="4" border="0"><tr>';

//if ($cnt >= $start && $cnt < $end)

if(isset($_GET['page'])&&($_GET['page'] != 1)) {

$pre = $_GET['page'] - 1;
	echo '<td align="left" width="38%"><a href="' . $_SERVER['PHP_SELF'] . '?app=graphics-gallery&page=' . $pre . '&folder=' . urlencode($_GET['folder']) . '"><big><b>Previous Page</b></big></a></td>';
	}

$pages = $total/$max2show;
$lastpage = ceil($pages);

echo '<td></td>';

if($page < $lastpage) {

$next = $page + 1;
echo '<td align="right" width="45%"><a href="' . $_SERVER['PHP_SELF'] . '?app=graphics-gallery&page=' . $next . '&folder=' . urlencode($_GET['folder']) . '"><big><b>Next Page</b></big></a></td>';

}

echo '</tr>
</table><br />';

for ($cnt = $start; $cnt < $end; $cnt++) {
$file = $files[$cnt];

$exten = explode('.',$file);


?>	




<table border="0" width="100%" align="center" cellpadding="4" cellspacing="4">
        <tr>
          <td valign="top" style="padding-right: 10px;" align="right"><a href="<?php echo $urlpath . $file; ?>" target="_blank" rel="lightbox" title="<?php echo $file; ?>"><img src="<?php echo $urlpath . $file; ?>" alt="<?php echo $file; ?>" width="230" height="230"></a></td>
          <td valign="top" align="left">


custom html code here


          </td>
        </tr>
      </table>


<table border="0" width="100%" align="center" cellpadding="4" cellspacing="4">
        <tr>
          <td>

<div id="divWildfirePost_<?php echo $idnum; ?>"></div>
<SCRIPT>
var pconf_<?php echo $idnum; ?>={
     defaultContent: "postContent_<?php echo $idnum; ?>",
     tabTextColor: "#2B2B2B",
     frameColor: "#757575",
     fontType: "Arial"
};
Wildfire.initPost("ProfileCMS", "divWildfirePost_<?php echo $idnum; ?>", 450, 130, pconf_<?php echo $idnum; ?>);
</SCRIPT>
</td>
         
        </tr>
      </table>



<br />
<hr />


<?
$idnum ++;
}//for

echo '<br /><table width="100%"  border="0" cellspacing="0" cellpadding="4" border="0"><tr>';

if(isset($_GET['page'])&&($_GET['page'] != 1)) {

$pre = $_GET['page'] - 1;
	echo '<td align="left" width="38%"><a href="' . $_SERVER['PHP_SELF'] . '?app=graphics-gallery&page=' . $pre . '&folder=' . urlencode($_GET['folder']) . '"><big><b>Previous Page</b></big></a></td>';
	}

echo '<td></td>';

if($page < $lastpage) {

$next = $page + 1;
echo '<td align="right" width="45%"><a href="' . $_SERVER['PHP_SELF'] . '?app=graphics-gallery&page=' . $next . '&folder=' . urlencode($_GET['folder']) . '"><big><b>Next Page</b></big></a></td>';

}

echo '</tr>
</table>';
?>



    </td>
  </tr>
</table>

Link to comment
Share on other sites

Hmmm.... Best advice is to use a Database unless you use __Line__ in front of every line and call it with PHP and use something like:

 

<?php
if (__line__ >= 60){
#code here
}
elseif (__line__ >= 120){
#code here
}
// Ect... Ect... Ect...
?>

 

Is there some reason why you cant use a database because if you can use one. Everything I do is always hosted on some type of database somewhere

Link to comment
Share on other sites

Post a snippet of code that you are trying to paginate.  I successfully paginated a text file using pointers inside the file, I used preg_match to get the info between the pointers and displayed it, for the numbers, I read how many pointers there were, printed the previous code, did a foreach loop to print the numbers, then printed the next code.

Link to comment
Share on other sites

Hey bud thanks for the reply..

 

<script type="text/JavaScript">a
<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
//-->
</script>



    

<table width="100%">
  <tr>
    <td><div align="center"><h1>Browse Folders</h1>
<?

$urlpath = "http://domain.com/graphicstest";
$cat = "/home/username/public_html/graphicstest";

$max2show = 3; //Amount you want to show per page

$numFolderColumns = 1;	// Number of columns of folder names you want to show on each row 

// END OF CONFIGURATION SECTION
// Do not edit below this line

// Folder support
if(isset($_GET['folder']))
{
$cat .= $_GET['folder'] . '/';
$urlpath .= $_GET['folder'] . '/';
}

$hook = opendir($cat) or die('cant open dir');
$total = 0;

if(!isset($_GET['page'])) $page = 1;
else $page = $_GET['page'];

$start = $max2show * $page - $max2show;
$end = $page * $max2show;

/* folder support */
$directories = array();
/* End folder support part */

$ext = array("jpg", "png", "jpeg", "gif");
while (false!==($file = readdir($hook))) {
$idnum = "1";
// Functionality to check folders added here
$fpath = $cat . $file;

if(is_dir($fpath))
{
  //echo 
	if($file != '.' && $file != '..')
	{
		array_push($directories, $file);
	}
}
// folder support ends here

for($i=0;$i<sizeof($ext);$i++)
{
	if (stristr($file, ".".$ext[$i])) //NOT case sensitive 
	{
		$files[] = $file; 
		$total++;
	}
}
}
closedir($hook);
natcasesort($files);
$files = array_values($files);

/* Modification part to display folders */
if(count($directories) > 0)
{

  
$loopCounter = 1;
foreach($directories as $directory)
{


	echo ' <a href="' . $_SERVER['PHP_SELF'] . '?page=1&folder=' . urlencode($directory) . '"><b>' . $directory . '</b></a> ~';




	$loopCounter += 1;
}

;
}

if(!empty($_GET['folder']))
{
echo '</div><span>Viewing subfolder: <b>' . $_GET['folder'] . '</b></span><br /><a href="/graphics-gallery"><b>Back To Gallery Index</b></a><br />';
}
/* End modification part */

if ($end > $total) { $end = $total; }

echo '<table width="100%"  border="0" cellspacing="0" cellpadding="4" border="0"><tr>';

//if ($cnt >= $start && $cnt < $end)

if(isset($_GET['page'])&&($_GET['page'] != 1)) {

$pre = $_GET['page'] - 1;
	echo '<td align="left" width="38%"><a href="' . $_SERVER['PHP_SELF'] . '?page=' . $pre . '&folder=' . urlencode($_GET['folder']) . '"><big><b>Previous Page</b></big></a></td>';
	}

$pages = $total/$max2show;
$lastpage = ceil($pages);

echo '<td></td>';

if($page < $lastpage) {

$next = $page + 1;
echo '<td align="right" width="45%"><a href="' . $_SERVER['PHP_SELF'] . '?page=' . $next . '&folder=' . urlencode($_GET['folder']) . '"><big><b>Next Page</b></big></a></td>';

}

echo '</tr>
</table><br />';

for ($cnt = $start; $cnt < $end; $cnt++) {
$file = $files[$cnt];

$exten = explode('.',$file);


?>	




<table border="0" width="100%" align="center" cellpadding="4" cellspacing="4">
        <tr>
          <td valign="top" style="padding-right: 10px;" align="right"><a href="<?php echo $urlpath . $file; ?>" target="_blank" rel="lightbox" title="<?php echo $file; ?>"><img src="<?php echo $urlpath . $file; ?>" alt="<?php echo $file; ?>" width="230" height="230"></a></td>
          <td valign="top" align="left">


custom html code here


          </td>
        </tr>
      </table>


<table border="0" width="100%" align="center" cellpadding="4" cellspacing="4">
        <tr>
          <td>

<div id="divWildfirePost_<?php echo $idnum; ?>"></div>
<SCRIPT>
var pconf_<?php echo $idnum; ?>={
     defaultContent: "postContent_<?php echo $idnum; ?>",
     tabTextColor: "#2B2B2B",
     frameColor: "#757575",
     fontType: "Arial"
};
Wildfire.initPost("ProfileCMS", "divWildfirePost_<?php echo $idnum; ?>", 450, 130, pconf_<?php echo $idnum; ?>);
</SCRIPT>
</td>
         
        </tr>
      </table>



<br />
<hr />


<?
$idnum ++;
}//for

echo '<br /><table width="100%"  border="0" cellspacing="0" cellpadding="4" border="0"><tr>';

if(isset($_GET['page'])&&($_GET['page'] != 1)) {

$pre = $_GET['page'] - 1;
	echo '<td align="left" width="38%"><a href="' . $_SERVER['PHP_SELF'] . '?page=' . $pre . '&folder=' . urlencode($_GET['folder']) . '"><big><b>Previous Page</b></big></a></td>';
	}

echo '<td></td>';

if($page < $lastpage) {

$next = $page + 1;
echo '<td align="right" width="45%"><a href="' . $_SERVER['PHP_SELF'] . '?page=' . $next . '&folder=' . urlencode($_GET['folder']) . '"><big><b>Next Page</b></big></a></td>';

}

echo '</tr>
</table>';
?>



    </td>
  </tr>
</table>

 

Hey ok i edited the code so that you can test it on your server create a folder called graphictest in your web root. then edit these 2 variables at top to reflect it

 

$urlpath = "http://domain.com/graphicstest";

$cat = "/home/username/public_html/graphicstest";

 

then after upload this script in that folder create a folder inside of that test folder and add some graphics and you will see what i mean .. Thanks

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.