Paging for directory listing in php
<p>I'm trying to get the paging for directory listing script.</p>

<p>Here is the original code for the function.
This function list all the mp3 files in the directory and some file information.</p>

<p><code>$songs</code> is holding the array infomation</p>

<p>original code</p>

<pre><code>function htmlSongs(&amp;$tmpl, $path_raw, $songs, $custom_pls = false, $c_pls_arr = null, $lofi = false, $various, $dir_write, $song_ratings) {
global $z_url_base, $z_self, $z_img_play, $z_img_lofi, $z_img_down,
    $z_admin, $z_img_new, $z_img_edit, $z_self_raw, $zc, $z_db,$img_src;    
$i = 0;
$check_boxes = false;

$diff = $zc['new_time']*60*60*24;

if (($z_admin &amp;&amp; $zc['cache']) || ($zc['playlists'] &amp;&amp; $zc['session_pls']) || $zc['play_sel'] || $zc['cmp_sel']) {
    $check_boxes = true;
}
$tmpl = str_replace('{$songs_form_opts}', "name='songs' method='post' action='${z_self}p=$path_raw'", $tmpl);

$temp_section = tmpGetSect($tmpl, "SONGROW");
$html = "";
$rating = ($z_db &amp;&amp; $zc['rating_files']);


foreach ($songs as $song =&gt; $opts) {
    $temp_song = $temp_section;
    $valign = ($opts['blurb']) ? "valign='top'" : "";
    $song_raw = getURLencodedPath($song);
    $song_title = formatSongTitle(basename($song));
    $temp_song = str_replace('{$row}', $i, $temp_song);
    $temp_song = str_replace('{$valign}', $valign, $temp_song);
    $t_blurb = ($dir_write) ? "${opts['blurb']} &lt;a href='${z_self_raw}&amp;amp;pl=".getURLencodedPath(basename($song))."&amp;amp;l=22&amp;amp;m=3'&gt;$z_img_edit&lt;/a&gt;" : $opts['blurb'];
    $temp_song = str_replace('{$song_blurb}', $t_blurb, $temp_song);
    $t_song_opts = "";
    $remote = false;

    if ($zc['fake'] &amp;&amp; isset($opts['fake'])) {
        $fi = ($zc['mp3_info']) ? "&lt;td colspan='4'&gt;&amp;nbsp;&lt;/td&gt;" : "";
        $temp_song = tmpDelSec($temp_song,"SONGINFO", $fi);
        $fi = ($rating) ? "&lt;td colspan='2'&gt;&amp;nbsp;&lt;/td&gt;" : "";
        $temp_song = tmpDelSec($temp_song,"SONGVOTE", $fi);
        $temp_song = tmpDelSec($temp_song,"SONGRATING");
        $t_song_title = preg_replace("/\.(".$zc['fake_ext'].")$/i","",$song_title);
    } else {
        $url_play = $url_end = "";

        if ($zc['mp3_info'] || $zc['mp3_id3']) {
            if ($zc['remote'] &amp;&amp; preg_match("/\.(".$zc['remote_ext'].")$/i", $song)) {
                $mp3 = new remoteFile($zc['mp3_dir']."/$song", $zc['mp3_info'], $zc['mp3_id3']);
                $remote = true;
            } else {
                $mp3 = new mp3($zc['mp3_dir']."/$song", $zc['mp3_info'], $zc['mp3_id3'], $zc['mp3_info_faster']);
            }
        }

        if ($check_boxes) {
            $checked = ($custom_pls &amp;&amp; in_array($song, $c_pls_arr)) ? " checked='checked'" : "";
            $t_song_opts .= "&lt;input type='checkbox' name='mp3s[]' value='$song_raw'$checked /&gt; &amp;nbsp; ";
        } else {
            $t_song_opts .= "&amp;nbsp;";
        }

        if ($zc['download']) {
            if ($remote) {
                if (isset($mp3-&gt;download)) $t_song_opts .= "&lt;a href='".$mp3-&gt;download."'&gt;$z_img_down&lt;/a&gt; &amp;nbsp;&amp;nbsp; ";
            } else {
                $surl = ($zc['stream_int']) ? "${z_self}l=12&amp;amp;p=$song_raw" : "$z_url_base/".getURLencodedPath2($song);
                $t_song_opts .= "&lt;a href='$surl&amp;Oauth=$newssid'&gt;$z_img_down&lt;/a&gt; &amp;nbsp;&amp;nbsp; ";
            }
        }

        if ($zc['play']) {
            $url_play = "&lt;a type=\"audio/mpeg\" title='$song_title' href='$mp3-&gt;url' &gt;";
            $url_end = "&lt;/a&gt;";
            if($mp3-&gt;url != ""){
                $t_song_opts .= "$url_play &lt;/a&gt; &amp;nbsp;";
            }else{
                $t_song_opts .= "";
            }
        }
        if ($zc['low']) {
            $tmp = "&amp;nbsp;&lt;a href='${z_self}l=8&amp;amp;p=";
            if (isset($opts['lofi'])) {
                $t_song_opts .= "$tmp".preg_replace("/\.(".$zc['ext_mus'].")$/i", $zc['low_suf'].".$1", $song_raw).
                    "&amp;amp;m=1'&gt;$z_img_lofi&lt;/a&gt; &amp;nbsp;";
            } elseif($zc['resample'] &amp;&amp; preg_match("/\.(".$zc['ext_enc'].")$/i", $song)) {
                $t_song_opts .= "$tmp$song_raw&amp;amp;m=6'&gt;$z_img_lofi&lt;/a&gt; &amp;nbsp;";
            }
        }
        if ($zc['new_highlight'] &amp;&amp; isset($opts['mtime']) &amp;&amp; ($now - $opts['mtime'] &lt; $diff)) {
            if ($zc['new_img']) {
                $new_end = $z_img_new;
                $new_beg = "";
            } else {
                $new_beg = $zc['new_beg'];
                $new_end = $zc['new_end'];
            }
        } else {
            $new_beg = $new_end = "";
        }

        $t_song_title = "$new_beg";
        if ($zc['mp3_id3'] &amp;&amp; $mp3-&gt;tag) {
            if ($various &amp;&amp; !empty($mp3-&gt;artist)) $t_song_title .= "$mp3-&gt;artist - ";
            $t_song_title .= $mp3-&gt;title;
        } else {
            $subdir_images = "";
            $t_song_title .= "$song_title";
        }

        $t_song_titles = "$new_beg";
        if ($zc['mp3_id3'] &amp;&amp; $mp3-&gt;tag) {
            if ($various &amp;&amp; !empty($mp3-&gt;artist)) $t_song_title .= "$mp3-&gt;artist - ";
            $t_song_titles .= $mp3-&gt;title;
        } else {
            //$t_song_titles .= "&lt;a href='$surl' type='audio/mpeg' title='$song_title'&gt;&lt;img src='$img_src' style='display:none' /&gt;&lt;/a&gt;";
            $t_song_titles .= "";
        }

        $t_song_title .= "$new_end";
        if ($zc['mp3_info']) {
            if ($mp3-&gt;info == 1) {
                $t_time = $mp3-&gt;time;
                $t_bitrate = "$mp3-&gt;bitrate kbps";
                $t_frequency = round($mp3-&gt;frequency/1000,1). " kHz";
                $t_size = sprintf("%.2f", round($mp3-&gt;filesize/1000000,2))." Mb";
            } else {
                $t_size = (!$remote) ? sprintf("%.2f", round($mp3-&gt;filesize/1000000,2))." Mb" : "&amp;nbsp;";
                $t_time = $t_bitrate = $t_frequency = "&amp;nbsp;";
            }
            $temp_song = str_replace('{$song_time}', $t_time, $temp_song);
            $temp_song = str_replace('{$song_bitrate}', $t_bitrate, $temp_song);
            $temp_song = str_replace('{$song_frequency}', $t_frequency, $temp_song);
            $temp_song = str_replace('{$song_size}', $t_size, $temp_song);
        } else {
            $temp_song = tmpDelSec($temp_song,"SONGINFO");
        }

        if ($rating) {
            $temp_song = str_replace('{$song_vote}', htmlVote($song), $temp_song);
            $rating = (!empty($song_ratings) &amp;&amp; isset($song_ratings[$song])) ? htmlVoteFormat($song_ratings[$song]) : "&amp;nbsp;";
            $temp_song = str_replace('{$song_rating}', $rating, $temp_song);
        } else {
            $temp_song = tmpDelSec($temp_song,"SONGVOTE");
            $temp_song = tmpDelSec($temp_song,"SONGRATING");
        }
    }
    $temp_song = str_replace('{$song_title}', $t_song_title, $temp_song);
    $temp_song = str_replace('{$song_titles}', $t_song_titles, $temp_song);
    $temp_song = str_replace('{$song_opts}', $t_song_opts, $temp_song);
    $temp_song = str_replace('{$pageshtml}', $t_pageshtml, $temp_song);

    $html .= $temp_song;
    $i = ++$i % 2;

}

$tmpl = tmpDelSec($tmpl,"SONGROW",$html);
$t_so_check = $t_so_sel = $t_so_pls = "";
if ($z_admin &amp;&amp; $zc['cache']) {
    $submit = ($custom_pls) ? _ZUPDATECUSTOM : _ZCREATECUSTOM;
    $t_so_check .= "&lt;input type='submit' value='$submit ' onClick=\"SubmitForm('songs','&amp;amp;l=3&amp;amp;z=3',false);\"/&gt;";
}

if ($check_boxes) {
    $t_so_check .= "&amp;nbsp; "._ZCHECK.": &amp;nbsp;&lt;a href='javascript:void 0;' onclick=\"CheckBoxes('songs',true);\"&gt;"._ZALL."&lt;/a&gt; | ".
        "&lt;a href='javascript:void 0;' onclick=\"CheckBoxes('songs',false);\"&gt;"._ZNONE."&lt;/a&gt;";

    if ($zc['play_sel'] || $zc['cmp_sel']) {
        $url_beg2 = " &amp;nbsp; &lt;a class='htrack' type='audio/mpeg'  href=\"javascript:CheckIt('songs',";
        $t_so_sel .= _ZSELECTED.": ";
        $err = _ZERR_SEL;
        if ($zc['play'] &amp;&amp; $zc['play_sel']) { $t_so_sel .= "$url_beg2'${z_self}l=8&amp;amp;m=7',true,'$err');\"&gt;$z_img_play&lt;/a&gt;"; }
        if ($lofi) { $t_so_sel .= "$url_beg2'${z_self}l=8&amp;amp;m=7&amp;amp;lf=true',true,'$err');\"&gt;$z_img_lofi&lt;/a&gt;"; }
        if ($zc['download'] &amp;&amp; $zc['cmp_sel']) { $t_so_sel .= "$url_beg2'&amp;amp;l=8&amp;amp;m=8',false,'$err');\"&gt;$z_img_down&lt;/a&gt;"; }
    }
}
$title = substr($path_raw,strrpos($path_raw,"/")+1);
$t_so_pls = ($zc['playlists']) ? htmlPlaylistFormElements('songs') : "&amp;nbsp;";
$tmpl = str_replace('{$row}',$i, $tmpl);
$tmpl = str_replace('{$so_check}',$t_so_check, $tmpl);
$tmpl = str_replace('{$so_select}',$t_so_sel, $tmpl);
$tmpl = str_replace('{$so_playlist}',$t_so_pls, $tmpl);
$tmpl = str_replace('{$movie_title}', $title, $tmpl);
</code></pre>

<p>Here is the some workaround to get the paging, this function is working but it's not showing the file information such as file name, time, size</p>

<p>This is the edited code.</p>

<pre><code>    function htmlSongs(&amp;$tmpl, $path_raw, $songs, $custom_pls = false, $c_pls_arr = null, $lofi = false, $various, $dir_write, $song_ratings) {
    global $z_url_base, $z_self, $z_img_play, $z_img_lofi, $z_img_down,
        $z_admin, $z_img_new, $z_img_edit, $z_self_raw, $zc, $z_db,$img_src;    
    $i = 0;
    $check_boxes = false;
    $diff = $zc['new_time']*60*60*24;

    if (($z_admin &amp;&amp; $zc['cache']) || ($zc['playlists'] &amp;&amp; $zc['session_pls']) || $zc['play_sel'] || $zc['cmp_sel']) {
        $check_boxes = true;
    }
    $tmpl = str_replace('{$songs_form_opts}', "name='songs' method='post' action='${z_self}p=$path_raw'", $tmpl);

    $temp_section = tmpGetSect($tmpl, "SONGROW");
    $html = "";
    $rating = ($z_db &amp;&amp; $zc['rating_files']);

$i = $stat_prev = 0;
$p = 1;
$currents = htmlspecialchars($_GET['showpage']);
$pages = array_chunk($songs, 10);
$t_pageshtml .= '&lt;center&gt;Page '.($currents+1).' of '.count($pages).'&amp;nbsp;&amp;nbsp;&lt;br&gt;Pages: ';
for($i=1; $i&lt; count($pages)+1; $i++){
$t_pageshtml .= '&lt;a href="?p='.htmlspecialchars($_GET["p"]).'&amp;showpage='.($i-1).'"&gt;'.$i.'&lt;/a&gt; &amp;nbsp;';
}
$t_pageshtml .= '&lt;/center&gt;';
$pgkey = (int)htmlspecialchars($_GET['showpage']);
$pages[$pgkey];

    foreach ($pages[$pgkey] as $song =&gt; $opts) {
        $temp_song = $temp_section;
        $valign = ($opts['blurb']) ? "valign='top'" : "";
        $song_raw = getURLencodedPath($song);
        $song_title = formatSongTitle(basename($song));
        $temp_song = str_replace('{$row}', $i, $temp_song);
        $temp_song = str_replace('{$valign}', $valign, $temp_song);
        $t_blurb = ($dir_write) ? "${opts['blurb']} &lt;a href='${z_self_raw}&amp;amp;pl=".getURLencodedPath(basename($song))."&amp;amp;l=22&amp;amp;m=3'&gt;$z_img_edit&lt;/a&gt;" : $opts['blurb'];
        $temp_song = str_replace('{$song_blurb}', $t_blurb, $temp_song);
        $t_song_opts = "";
        $remote = false;

        if ($zc['fake'] &amp;&amp; isset($opts['fake'])) {
            $fi = ($zc['mp3_info']) ? "&lt;td colspan='4'&gt;&amp;nbsp;&lt;/td&gt;" : "";
            $temp_song = tmpDelSec($temp_song,"SONGINFO", $fi);
            $fi = ($rating) ? "&lt;td colspan='2'&gt;&amp;nbsp;&lt;/td&gt;" : "";
            $temp_song = tmpDelSec($temp_song,"SONGVOTE", $fi);
            $temp_song = tmpDelSec($temp_song,"SONGRATING");
            $t_song_title = preg_replace("/\.(".$zc['fake_ext'].")$/i","",$song_title);
        } else {
            $url_play = $url_end = "";

            if ($zc['mp3_info'] || $zc['mp3_id3']) {
                if ($zc['remote'] &amp;&amp; preg_match("/\.(".$zc['remote_ext'].")$/i", $song)) {
                    $mp3 = new remoteFile($zc['mp3_dir']."/$song", $zc['mp3_info'], $zc['mp3_id3']);
                    $remote = true;
                } else {
                    $mp3 = new mp3($zc['mp3_dir']."/$song", $zc['mp3_info'], $zc['mp3_id3'], $zc['mp3_info_faster']);
                }
            }

            if ($check_boxes) {
                $checked = ($custom_pls &amp;&amp; in_array($song, $c_pls_arr)) ? " checked='checked'" : "";
                $t_song_opts .= "&lt;input type='checkbox' name='mp3s[]' value='$song_raw'$checked /&gt; &amp;nbsp; ";
            } else {
                $t_song_opts .= "&amp;nbsp;";
            }

            if ($zc['download']) {
                if ($remote) {
                    if (isset($mp3-&gt;download)) $t_song_opts .= "&lt;a href='".$mp3-&gt;download."'&gt;$z_img_down&lt;/a&gt; &amp;nbsp;&amp;nbsp; ";
                } else {
                    $surl = ($zc['stream_int']) ? "${z_self}l=12&amp;amp;p=$song_raw" : "$z_url_base/".getURLencodedPath2($song);
                    $t_song_opts .= "&lt;a href='$surl&amp;Oauth=$newssid'&gt;$z_img_down&lt;/a&gt; &amp;nbsp;&amp;nbsp; ";
                }
            }

            if ($zc['play']) {
                $url_play = "&lt;a type=\"audio/mpeg\" title='$song_title' href='$mp3-&gt;url' &gt;";
                $url_end = "&lt;/a&gt;";
                if($mp3-&gt;url != ""){
                    $t_song_opts .= "$url_play &lt;/a&gt; &amp;nbsp;";
                }else{
                    $t_song_opts .= "";
                }
            }
            if ($zc['low']) {
                $tmp = "&amp;nbsp;&lt;a href='${z_self}l=8&amp;amp;p=";
                if (isset($opts['lofi'])) {
                    $t_song_opts .= "$tmp".preg_replace("/\.(".$zc['ext_mus'].")$/i", $zc['low_suf'].".$1", $song_raw).
                        "&amp;amp;m=1'&gt;$z_img_lofi&lt;/a&gt; &amp;nbsp;";
                } elseif($zc['resample'] &amp;&amp; preg_match("/\.(".$zc['ext_enc'].")$/i", $song)) {
                    $t_song_opts .= "$tmp$song_raw&amp;amp;m=6'&gt;$z_img_lofi&lt;/a&gt; &amp;nbsp;";
                }
            }
            if ($zc['new_highlight'] &amp;&amp; isset($opts['mtime']) &amp;&amp; ($now - $opts['mtime'] &lt; $diff)) {
                if ($zc['new_img']) {
                    $new_end = $z_img_new;
                    $new_beg = "";
                } else {
                    $new_beg = $zc['new_beg'];
                    $new_end = $zc['new_end'];
                }
            } else {
                $new_beg = $new_end = "";
            }

            $t_song_title = "$new_beg";
            if ($zc['mp3_id3'] &amp;&amp; $mp3-&gt;tag) {
                if ($various &amp;&amp; !empty($mp3-&gt;artist)) $t_song_title .= "$mp3-&gt;artist - ";
                $t_song_title .= $mp3-&gt;title;
            } else {
                $subdir_images = "";
                $t_song_title .= "$song_title";
            }

            $t_song_titles = "$new_beg";
            if ($zc['mp3_id3'] &amp;&amp; $mp3-&gt;tag) {
                if ($various &amp;&amp; !empty($mp3-&gt;artist)) $t_song_title .= "$mp3-&gt;artist - ";
                $t_song_titles .= $mp3-&gt;title;
            } else {
                //$t_song_titles .= "&lt;a href='$surl' type='audio/mpeg' title='$song_title'&gt;&lt;img src='$img_src' style='display:none' /&gt;&lt;/a&gt;";
                $t_song_titles .= "";
            }

            $t_song_title .= "$new_end";
            if ($zc['mp3_info']) {
                if ($mp3-&gt;info == 1) {
                    $t_time = $mp3-&gt;time;
                    $t_bitrate = "$mp3-&gt;bitrate kbps";
                    $t_frequency = round($mp3-&gt;frequency/1000,1). " kHz";
                    $t_size = sprintf("%.2f", round($mp3-&gt;filesize/1000000,2))." Mb";
                } else {
                    $t_size = (!$remote) ? sprintf("%.2f", round($mp3-&gt;filesize/1000000,2))." Mb" : "&amp;nbsp;";
                    $t_time = $t_bitrate = $t_frequency = "&amp;nbsp;";
                }
                $temp_song = str_replace('{$song_time}', $t_time, $temp_song);
                $temp_song = str_replace('{$song_bitrate}', $t_bitrate, $temp_song);
                $temp_song = str_replace('{$song_frequency}', $t_frequency, $temp_song);
                $temp_song = str_replace('{$song_size}', $t_size, $temp_song);
            } else {
                $temp_song = tmpDelSec($temp_song,"SONGINFO");
            }

            if ($rating) {
                $temp_song = str_replace('{$song_vote}', htmlVote($song), $temp_song);
                $rating = (!empty($song_ratings) &amp;&amp; isset($song_ratings[$song])) ? htmlVoteFormat($song_ratings[$song]) : "&amp;nbsp;";
                $temp_song = str_replace('{$song_rating}', $rating, $temp_song);
            } else {
                $temp_song = tmpDelSec($temp_song,"SONGVOTE");
                $temp_song = tmpDelSec($temp_song,"SONGRATING");
            }
        }
        $temp_song = str_replace('{$song_title}', $t_song_title, $temp_song);
        $temp_song = str_replace('{$song_titles}', $t_song_titles, $temp_song);
        $temp_song = str_replace('{$song_opts}', $t_song_opts, $temp_song);
        $temp_song = str_replace('{$pageshtml}', $t_pageshtml, $temp_song);

        $html .= $temp_song;
        $i = ++$i % 2;
        $p++;
    }

    $tmpl = tmpDelSec($tmpl,"SONGROW",$html);
    //$t_pageshtml = 'UUUU';
    $t_so_check = $t_so_sel = $t_so_pls = "";
    if ($z_admin &amp;&amp; $zc['cache']) {
        $submit = ($custom_pls) ? _ZUPDATECUSTOM : _ZCREATECUSTOM;
        $t_so_check .= "&lt;input type='submit' value='$submit ' onClick=\"SubmitForm('songs','&amp;amp;l=3&amp;amp;z=3',false);\"/&gt;";
    }

    if ($check_boxes) {
        $t_so_check .= "&amp;nbsp; "._ZCHECK.": &amp;nbsp;&lt;a href='javascript:void 0;' onclick=\"CheckBoxes('songs',true);\"&gt;"._ZALL."&lt;/a&gt; | ".
            "&lt;a href='javascript:void 0;' onclick=\"CheckBoxes('songs',false);\"&gt;"._ZNONE."&lt;/a&gt;";

        if ($zc['play_sel'] || $zc['cmp_sel']) {
            $url_beg2 = " &amp;nbsp; &lt;a class='htrack' type='audio/mpeg'  href=\"javascript:CheckIt('songs',";
            $t_so_sel .= _ZSELECTED.": ";
            $err = _ZERR_SEL;
            if ($zc['play'] &amp;&amp; $zc['play_sel']) { $t_so_sel .= "$url_beg2'${z_self}l=8&amp;amp;m=7',true,'$err');\"&gt;$z_img_play&lt;/a&gt;"; }
            if ($lofi) { $t_so_sel .= "$url_beg2'${z_self}l=8&amp;amp;m=7&amp;amp;lf=true',true,'$err');\"&gt;$z_img_lofi&lt;/a&gt;"; }
            if ($zc['download'] &amp;&amp; $zc['cmp_sel']) { $t_so_sel .= "$url_beg2'&amp;amp;l=8&amp;amp;m=8',false,'$err');\"&gt;$z_img_down&lt;/a&gt;"; }
        }
    }
    $title = substr($path_raw,strrpos($path_raw,"/")+1);
    $t_so_pls = ($zc['playlists']) ? htmlPlaylistFormElements('songs') : "&amp;nbsp;";
    $tmpl = str_replace('{$row}',$i, $tmpl);
    $tmpl = str_replace('{$so_check}',$t_so_check, $tmpl);
    $tmpl = str_replace('{$so_select}',$t_so_sel, $tmpl);
    $tmpl = str_replace('{$so_playlist}',$t_so_pls, $tmpl);
    $tmpl = str_replace('{$movie_title}', $title, $tmpl);
    $tmpl = str_replace('{$pages_html}', $t_pageshtml, $tmpl);

}
</code></pre>

<p>This is the code for paging</p>

<pre><code>$i = $stat_prev = 0;
$p = 1;
$currents = htmlspecialchars($_GET['showpage']);
$pages = array_chunk($songs, 10);
$t_pageshtml .= '&lt;center&gt;Page '.($currents+1).' of '.count($pages).'&amp;nbsp;&amp;nbsp;&lt;br&gt;Pages: ';
for($i=1; $i&lt; count($pages)+1; $i++){
$t_pageshtml .= '&lt;a href="?p='.htmlspecialchars($_GET["p"]).'&amp;showpage='.($i-1).'"&gt;'.$i.'&lt;/a&gt; &amp;nbsp;';
}
$t_pageshtml .= '&lt;/center&gt;';
$pgkey = (int)htmlspecialchars($_GET['showpage']);
$pages[$pgkey];
</code></pre>

<p>i think something wrong here</p>

<p>original code</p>

<pre><code>foreach ($songs as $song =&gt; $opts)
</code></pre>

<p>edited code</p>

<pre><code> foreach ($pages[$pgkey] as $song =&gt; $opts) {
</code></pre>

<p><strong>OK</strong></p>

<p>I solved the problem my self.</p>

<p>here is the solution</p>

<p>i use array_slice</p>

<pre><code>$i = $stat_prev = 0;
$p = 1;
$currents = htmlspecialchars($_GET['showpage']);
$pages = array_chunk($songs, 10);
$t_pageshtml .= '&lt;center&gt;Page '.($currents+1).' of '.count($pages).'&amp;nbsp;&amp;nbsp;&lt;br&gt;Pages: ';
for($i=1; $i&lt; count($pages)+1; $i++){
$t_pageshtml .= '&lt;a href="?p='.htmlspecialchars($_GET["p"]).'&amp;showpage='.($i-1).'"&gt;'.$i.'&lt;/a&gt; &amp;nbsp;';
}
$t_pageshtml .= '&lt;/center&gt;';
$pgkey = (int)htmlspecialchars($_GET['showpage']);

$songs = array_slice($songs, $pgkey."0",10);

    foreach ($songs as $song =&gt; $opts ) {
</code></pre>
