0
我的分頁PHP腳本有問題。 第一頁完美地工作,但接下來的頁面是空白的。 Config.php包含像主機等數據庫設置 請幫我解決我的問題。 在此先感謝。來自MySQL的PHP分頁
這裏是我的代碼:
include 'config.php';
mysql_connect($iplogow, $userlogow, $haslologow) or die("Mysql error: " . mysql_error());
mysql_select_db($bazalogow)or die("Błąd bazy danych: " . mysql_error());
echo '<br>
<table class="table table-bordered table-striped" width="500px">
<thead>
<tr>
<th>table1</th>
<th>table2</th>
<th>table3</th>
<th>table4</th>
<th>table5</th>
<th>table6</th>
<th>table7</th>
</tr></thead>';
$result = mysql_query("SELECT Count(id) FROM `logi`");
$row = mysql_fetch_row($result);
$count_users = $row[0];
$per_page = 10;
$pages = ceil($count_users/$per_page);
$current_page = !isset($_GET['page']) ? 1 : (int)clear($_GET['page']);
if($current_page < 1 || $current_page > $pages) {
$current_page = 1;
}
if($count_users > 0) {
$result = mysql_query("SELECT * FROM `logi` ORDER BY `id` DESC LIMIT ".($per_page*($current_page-1)).", ".$per_page);
while($row = mysql_fetch_assoc($result)) {
echo '<tr>
<td>'.$row['nick'].'</td>
<td>'.$row['ip'].'</td>
<td>'.$row['password'].'</td>
<td>'.$row['productid'].'</td>
<td>'.$row['client'].'</td>
<td>'.$row['date'].'</td>
<td>'.$row['hour'].'</td>
</tr>';
}
} else {
echo '<tr>
<td colspan="3" style="text-align:center">Niestety nie znaleziono żadnych ataków.</td>
</tr>';
}
echo '</table>';
if($pages > 0) {
echo '<p>';
if($pages < 11) {
for($i = 1; $i <= $pages; $i++) {
if($i == $current_page) {
echo '<b>['.$current_page.']</b> ';
} else {
echo '<a href="ataki.php?page='.$i.'">['.$i.']</a> ';
}
}
} elseif($current_page > 10) {
echo '<a href="ataki.php?page=1">[1]</a> ';
echo '<a href="ataki.php?page=2">[2]</a> ';
echo '[...] ';
for($i = ($current_page-3); $i <= $current_page; $i++) {
if($i == $current_page) {
echo '<b>['.$current_page.']</b> ';
} else {
echo '<a href="ataki.php?page='.$i.'">['.$i.']</a> ';
}
}
for($i = ($current_page+1); $i <= ($current_page+3); $i++) {
if($i > ($pages)) break;
if($i == $current_page) {
echo '<b>['.$current_page.']</b> ';
} else {
echo '<a href="ataki.php?page='.$i.'">['.$i.']</a> ';
}
}
if($current_page < ($pages-4)) {
echo '[...] ';
echo '<a href="ataki.php?page='.($pages-1).'">['.($pages-1).']</a> ';
echo '<a href="ataki.php?page='.$pages.'">['.$pages.']</a> ';
} elseif($current_page == ($pages-4)) {
echo '[...] ';
echo '<a href="ataki.php?page='.$pages.'">['.$pages.']</a> ';
}
} else {
for($i = 1; $i <= 11; $i++) {
if($i == $current_page) {
if($i > ($pages)) break;
echo '<b>['.$current_page.']</b> ';
} else {
echo '<a href="ataki.php?page='.$i.'">['.$i.']</a> ';
}
}
if($pages > 12) {
echo '[...] ';
echo '<a href="ataki.php?page='.($pages-1).'">['.($pages-1).']</a> ';
echo '<a href="ataki.php?page='.$pages.'">['.$pages.']</a> ';
} elseif($pages == 12) {
echo '[...] ';
echo '<a href="ataki.php?page=12">[12]</a> ';
}
}
echo '</p>';
}
?>
什麼最近已經改變了嗎?你有什麼試圖解決你的問題?將不勝感激 – Resitive
這是從互聯網劇本:(我只改變數據庫通過,和表設計(引導)。PS時,我鍵入myserver.com/script.php?page=1也有空白頁。myserver。 com/script.php完美地工作... –
你包含了'clear()'函數嗎?看看這行:'$ current_page =!isset($ _ GET ['page'])?1:(int)clear($ _GET ['page']);'如果你沒有包含這個函數,那麼你在執行腳本時會得到一個致命的錯誤,嘗試去除clear(),看看會發生什麼,改變後的行應該是' $ current_page =!isset($ _ GET ['page'])?1:$ _GET ['page'];' –