Php dynamic page pagination
<p>So i have this page which lists '.txt' file contents on the website. I tried to paginate it, but it doesn't work. I'd like to have only one story per page (one story is data[0] . data[1])
The page is called to the browser via ajax.
Here is my code:</p>

<pre><code>&lt;?php
$dataArray = array();
//Number of chars for the string
$num = 500;
$dir = '../php/biralas_tortenetek/';
$willcount = readdir(opendir($dir));
$totfiles = count(readdir(opendir($dir)));
//Check if &lt;/div&gt;DIR e&lt;/div&gt;xists
if ($handle = opendir($dir)) {
    //Loop over the directory
    while (false !== ($file = readdir($handle))) {
        //Strip out the . and .. files
        if ($file != "." &amp;&amp; $entry != "..") {
            //Store file contents
            $filecontent = file_get_contents($dir . $file);
            //Split the content and store in array
            $length = strlen($filecontent);
            $dataArray[] = array(substr($filecontent, 0, $num), substr($filecontent, $num, $length ));

        }
    }
    //close the dir
    closedir($handle);
}


?&gt;&lt;?php 
$page = isset($_GET['page']) ? $_GET['page']-1 : 0;
echo "&lt;br/&gt;";
for($x=$page*1; $x &lt; $totfiles &amp;&amp; $x &lt; ($page+1)*12; $x++)
{
    foreach($dataArray as $data) { ?&gt;
        &lt;div class="visible"&gt;
            &lt;?php echo $data[0] . $data[1]; ?&gt;
        &lt;/div&gt;&lt;?php } ?&gt;
&lt;/div&gt;
&lt;?php }
for($page=1; ($page-1)*12 &lt; $totfiles; $page++)
{
    echo "&lt;div class='lapozo'&gt;&lt;a onclick='story_changepage($page);' href='../html/blog.php#tortenetek?page=$page'&gt;$page&lt;/a&gt;&lt;/div&gt;"; 
}
?&gt;
</code></pre>

<p>So again, the goal is to have only one story per page.
Thanks!</p>
