skot Posted January 11, 2009 Share Posted January 11, 2009 Hi. I've just managed to get a flash mp3 player preview working for my music site. The only problem is, at the moment there are 669 results returned on one page. So 670 flash objects are loaded at once! How can I introduce pagenation to an array of returned results? I want to limit results to say, 50 per page, whilst having the ability to move to the next and previous page, etc. Does anyone have a snippet or something that will start me going? The page in question can be seen at http://m.bridgey.net/indexn.php but I wouldn't click it unless you have a decent PC / net connection! Source code follows:- <?php include ("mcount.php"); function sortByDate($b, $a) { if ($a['dateSort'] == $b['dateSort']) { return 0; } return ($a['dateSort'] < $b['dateSort'])? -1 : 1; } //Valid extensions $valid_extensions = array ('mp3', 'wma'); $path = '.'; $dirArray = array(); // set timezone to GMT for all time fields putenv("TZ=GB/GMT"); // open dir $myDirectory = opendir($path); // fetch entries while($fileName = readdir($myDirectory)) { //Only process files if (!is_dir($path.'/'.$fileName)) { //Only process files with valid extensions $ext = strtolower(array_pop(explode(".", ($fileName)))); if (in_array($ext, $valid_extensions)) { $fileIdx = count($dirArray); $size = filesize($fileName); $totalSize += $size; $dirArray[$fileIdx]['name'] = $fileName; $dirArray[$fileIdx]['ext'] = $ext; $dirArray[$fileIdx]['dateSort'] = date('YmdHi', filemtime($fileName)); $dirArray[$fileIdx]['date'] = date('d/m/Y @ H:i', filemtime($fileName)); $dirArray[$fileIdx]['size'] = round((filesize($fileName) / 1024 / 1024), 2); } } } $sizecount = round(($totalSize/ 1024 / 1024), 2); $sizecountgb = round(($totalSize/ 1024 / 1024 / 1024), 2); // close dir closedir($myDirectory); //Sort by key usort($dirArray, 'sortByDate'); echo "<font face=verdana size=3 color=#F8F304><B>"; echo ":: To download right click on a track and 'save as...'</B><br>\n"; echo ":: To upload click the link at the top-right.</font><br>\n"; echo "<p align=\"center\"><font face=verdana size=2 color=white><b>Stats:</b> There are currently a total of <b>" . count($dirArray) . "</b> tracks here, totalling <b>" . $sizecount . " MB</b> in size <i>(which is about ". $sizecountgb ." GB). <b>". $hits[0] ."</b> of you have been here since Aug '08..</i></font></p><p align=\"center\"><font face=tahoma size=3 color=white>Hit Control + F to search - <a style=\"color:white\" href=\"javascript:bookmarksite('Bangin Trance, House & Electronica Tracks @ Bridgey.net', 'http://m.bridgey.net')\">Click here to add to bookmarks/favourites</a></font><br><br>\n"; // print header row echo "<center>\n"; echo "<table width=\"98%\" border=\"1\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\" bordercolor=\"#183041\">\n"; echo "<tr align=\"left\" background=\"http://bridgey.net/img/row_bg.gif\">\n"; echo "<th align=\"left\">Name / Preview</th>\n"; echo "<th align=\"center\">Type</th>\n"; echo "<th align=\"center\">File Size</th>\n"; echo "<th align=\"center\">Date Added</th>\n"; //echo "<th align=\"center\">Download?</th>\n"; echo "</tr>\n"; // print results foreach ($dirArray as $file) { echo "<tr background=\"http://bridgey.net/img/row_bg.gif\">\n"; echo "<td align=\"left\" background=\"http://bridgey.net/img/row_bg.gif\">"; echo "<font face=\"verdana\" size=\"2\" color=\"#D9F4FD\"><b> "; echo "<a href=\"{$file['name']}\"><img src=\"http://www.bridgey.net/img/star.gif\" border=\"0\">"; echo $file['name'] . "</a></b></font><br><object type=\"application/x-shockwave-flash\" data=\"http://bridgey.net/joomla/mambots/content/wp_player.swf\" id=\"audioplayer2\" width=\"290\" height=\"24\"><param name=\"movie\" value=\"http://bridgey.net/joomla/mambots/content/wp_player.swf\"><param name=\"FlashVars\" value=\"playerID=1&soundFile= {$file['name']}&autostart=no\"><param name=\"quality\" value=\"high\"><param name=\"menu\" value=\"false\"><param name=\"wmode\" value=\"transparent\"></object></td>\n"; echo "<td align=\"center\" background=\"http://bridgey.net/img/row_bg.gif\">{$file['ext']}</td>\n"; echo "<td align=\"center\" background=\"http://bridgey.net/img/row_bg.gif\">{$file['size']} " . MB ."</td>\n"; echo "<td align=\"center\" background=\"http://bridgey.net/img/row_bg.gif\">{$file['date']}</td>\n"; //echo "<td align=\"center\" background=\"http://bridgey.net/img/row_bg.gif\"><form name=\"download\" method=\"post\" action=\"download.php\"><input name=\"fileName\" type=\"hidden\" value=\"http://bridgey.net/music/{$file['name']}\"><input type=\"submit\" name=\"DL\" id=\"DL\" value=\"DL\" style=\"border:none #000000; background-color:#0099FF; outline:none; text-align:center; font-family:tahoma; font-size:14px\" /></form></td>\n"; echo "</tr>\n"; } echo "</table>\n"; echo "</center><br clear=\"all\">\n"; ?> Link to comment https://forums.phpfreaks.com/topic/140385-pagenating-array-results-not-mysql/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.