I want to make pagination for videos since i have much videos and i cannot load all in the same page, i have a function which displays all videos in the directory and than i limited it only to show first 6.

How do i make the pagination so when im on page 2 to show the next 6 videos ?
here is the full function

function video($path) {
    $folder = "videos/$path";
    $i = 0;
    if (is_dir($folder)) {
        if ($handle = opendir($folder)) {
            while (($file = readdir($handle)) != FALSE) {
                if ($file === "." || $file === ".." || $file === "index.html") { continue; }
                if (!in_array($file, array('.', '..')) && !is_dir($folder.$file))
                    $i++;
                    if($i <= 6) {
                        ?>
                        <div onclick=""style="-webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -o-user-select: none; user-select: none; ">
                        <a href="view_video.php?videoID=<?= base64_encode(base64_encode($file)); ?>">
                        <video width="500" no-controls preload="auto">
                        <source src="<?= $folder ?>/<?= $file ?>" type="video/mp4">
                        <source src="<?= $folder ?>/<?= $file ?>" type="video/ogg">
                        Your browser does not support HTML5 video.
                        </video>
                        </a>
                        </div>
                        <?php
                    }
                }
                closedir($handle);
        }
    }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.