0
所以我有這個頁面列出網站上的'.txt'文件內容。我試圖分頁,但它不起作用。我想每頁只有一個故事(一個故事是數據[0] .data [1]) 該頁面通過ajax調用到瀏覽器。 這裏是我的代碼:Php動態頁面分頁
<?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>";
}
?>
所以,再一次,我們的目標是讓每個頁面只有一個故事。 謝謝!
「我試圖進行分頁,但它不工作」,是什麼不起作用?任何錯誤? – Tomer 2012-07-05 12:08:05
它只顯示1頁(這是正確的,因爲它設置爲顯示12層),當我點擊它時,它複製當前頁面。我試圖將它設置爲1個故事/頁面,但沒有成功。 – trisztann 2012-07-05 12:30:33