2016-02-23 70 views
0

我很公平的noob當涉及到PHP和只是想知道如何我可以讓我的表分裂成頁面,因爲它有超過200,000記錄在數據庫中,如果有可能轉到表格的下一個/上一個頁面而不刷新網頁?移動到php桌面的下一個頁面沒有刷新

這是我的表,任何建議非常感謝!

a<?php 
 
$query = "SELECT * FROM aliases where client_id='$userid' ORDER BY time_edit DESC"; 
 
$result = mysql_query($query); 
 
if ($result->num_rows > 0) { 
 
\t echo "<table border=1>"; 
 
\t echo "<tr align=center>"; 
 
\t echo "<th width=25%>Alias</th>"; 
 
\t echo "<th width=25%>Times Used</th>"; 
 
\t echo "<th width=25%>First Used</th>"; 
 
\t echo "<th width=25%>Last Used</th>"; 
 
\t echo "</tr>"; 
 
\t echo "<tr><td>No Results</td></tr>"; 
 
} 
 
\t echo "<table border=1>"; 
 
\t echo "<tr>"; 
 
\t echo "<th width=25%>Alias</th>"; 
 
\t echo "<th width=25%>Times Used</th>"; 
 
\t echo "<th width=25%>First Used</th>"; 
 
\t echo "<th width=25%>Last Used</th>"; 
 
\t echo "</tr>"; 
 
while ($row = mysql_fetch_assoc($result)) { 
 
$timesused=$row['num_used']; 
 
$alias=$row['alias']; 
 
$alias=htmlentities($alias); 
 
$firstused=$row['time_add']; 
 
$firstused = date('d M Y H:i:s', $firstused); 
 
$lastused=$row['time_edit']; 
 
$lastused = date('d M Y H:i:s', $lastused); 
 
\t echo "<tr align=center>"; 
 
\t echo "<td>$alias</td>"; 
 
\t echo "<td>$timesused</td>"; 
 
\t echo "<td>$firstused</td>"; 
 
\t echo "<td>$lastused</td>"; 
 
\t echo "</tr>"; 
 
} 
 
\t echo "</table>"; 
 
?>

+0

檢出數據表插件並使用其服務器端分頁。 https://www.datatables.net/ – WillardSolutions

+0

看看這個ajax分頁(http://www.sitepoint.com/pagination-jquery-ajax-php/) –

+0

Datatables或類似的jsvascript插件肯定...與json飼料併爲這麼多的數據啓用服務器端處理選項 – charlietfl

回答

0

添加一個類你的細胞:

a<?php 
$query = "SELECT * FROM aliases where client_id='$userid' ORDER BY time_edit DESC"; 
$result = mysql_query($query); 
if ($result->num_rows > 0) { 
    echo "<table border=1>"; 
    echo "<tr align=center>"; 
    echo "<th width=25%>Alias</th>"; 
    echo "<th width=25%>Times Used</th>"; 
    echo "<th width=25%>First Used</th>"; 
    echo "<th width=25%>Last Used</th>"; 
    echo "</tr>"; 
    echo "<tr><td>No Results</td></tr>"; 
} 
    echo "<table border=1>"; 
    echo "<tr>"; 
    echo "<th width=25%>Alias</th>"; 
    echo "<th width=25%>Times Used</th>"; 
    echo "<th width=25%>First Used</th>"; 
    echo "<th width=25%>Last Used</th>"; 
    echo "</tr>"; 
    $countRow = 0; 
    $class = 1; 
while ($row = mysql_fetch_assoc($result)) { 
$countRow += 1; 
$timesused=$row['num_used']; 
$alias=$row['alias']; 
$alias=htmlentities($alias); 
$firstused=$row['time_add']; 
$firstused = date('d M Y H:i:s', $firstused); 
$lastused=$row['time_edit']; 
$lastused = date('d M Y H:i:s', $lastused); 
    echo "<tr align=center>"; 
    echo "<td class='visible".$class.">$alias</td>"; 
    echo "<td class='visible".$class.">$timesused</td>"; 
    echo "<td class='visible".$class.">$firstused</td>"; 
    echo "<td class='visible".$class.">$lastused</td>"; 
    echo "</tr>"; 
    if($countRow == 50){ $class += 1; $countRow = 0; } 
} 
    echo "</table>"; 
?> 

,並在客戶端使用JavaScript,jQuery的還是要隱藏或顯示他們什麼......

有插件可以爲你做前面評論... 這不是最好的答案,但我希望它可以幫助你。