atlanta Posted November 7, 2007 Share Posted November 7, 2007 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 https://forums.phpfreaks.com/topic/76311-pagination-help/ Share on other sites More sharing options...
atlanta Posted November 7, 2007 Author Share Posted November 7, 2007 Anybody??? Link to comment https://forums.phpfreaks.com/topic/76311-pagination-help/#findComment-386438 Share on other sites More sharing options...
Crew-Portal Posted November 7, 2007 Share Posted November 7, 2007 http://www.phpfreaks.com/tutorials/43/0.php PHPFreaks Does most of the work for you before you even need it! Please check the Tutorials Link to comment https://forums.phpfreaks.com/topic/76311-pagination-help/#findComment-386439 Share on other sites More sharing options...
atlanta Posted November 7, 2007 Author Share Posted November 7, 2007 i know i have read over the tutorial i know how to do it with mysql like nothing.. but this script doesnt use a database so its a little different thats why i asked for help on it Link to comment https://forums.phpfreaks.com/topic/76311-pagination-help/#findComment-386442 Share on other sites More sharing options...
Crew-Portal Posted November 7, 2007 Share Posted November 7, 2007 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 https://forums.phpfreaks.com/topic/76311-pagination-help/#findComment-386444 Share on other sites More sharing options...
HaLo2FrEeEk Posted November 7, 2007 Share Posted November 7, 2007 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 https://forums.phpfreaks.com/topic/76311-pagination-help/#findComment-386519 Share on other sites More sharing options...
atlanta Posted November 7, 2007 Author Share Posted November 7, 2007 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 https://forums.phpfreaks.com/topic/76311-pagination-help/#findComment-386831 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.