所以我有这个页面,其中列出了网站上的“.txt”文件内容。我试图对其进行分页,但它不起作用。我希望每页只有一个故事(一个故事是 data[0] . data[1]) 该页面通过 ajax 被调用到浏览器。这是我的代码:
<?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 </div>DIR e</div>xists
if ($handle = opendir($dir)) {
//Loop over the directory
while (false !== ($file = readdir($handle))) {
//Strip out the . and .. files
if ($file != "." && $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);
}
?><?php
$page = isset($_GET['page']) ? $_GET['page']-1 : 0;
echo "<br/>";
for($x=$page*1; $x < $totfiles && $x < ($page+1)*12; $x++)
{
foreach($dataArray as $data) { ?>
<div class="visible">
<?php echo $data[0] . $data[1]; ?>
</div><?php } ?>
</div>
<?php }
for($page=1; ($page-1)*12 < $totfiles; $page++)
{
echo "<div class='lapozo'><a onclick='story_changepage($page);' href='../html/blog.php#tortenetek?page=$page'>$page</a></div>";
}
?>
同样,目标是每页只有一个故事。谢谢!