我有一个脚本可以计算它在页面上看到的记录数:
<script>
document.write(document.getElementById('moon').rows.length-1);
document.write (' ');
document.write (' of ');
document.write (' ');
document.write(document.getElementById('moon').rows.length-1);
document.write (' pages');
</script>
我将如何使用它一次对 10 条记录进行分页?也许使用诸如display:none
或之类的样式,然后链接到“页面”计数上的这些隐藏的 div。
谢谢
编辑:
我曾尝试使用 PHP Mysql Query 来使用 num_rows 执行此操作,但即使我获取数据,它也总是会抛出错误!
第二次编辑
好的,我正在提取信息并显示它:
<table class="std" id="moon" border="0" cellpadding="0" cellspacing="0">
<tr>
<?php
$pcounter = 1;
$userID = LedDB::getInstance()->get_user_id_by_name($_SESSION['user']);
$presult = LedDB::getInstance()->get_page_by_campaign_id($campaignID);
$i=0;
while ($row = mysqli_fetch_array($presult)):
$style = "";
if($i%2==0)
{
$style = 'style="background-color: #EFEFEF"';
}
echo "<tr ".$style.">";
echo "<td class='camp' style='padding-left:10px;'><b><a href='editPage.php?pageID=" .htmlentities($row['pid']) ."&campaignID=" .htmlentities($row['campaignid']) ."' class='camp'> Page" . $pcounter . "</a></b></td>";
echo "<td style='padding-left:10px;'></td>";
echo "<td style='padding-left:10px;'></td>";
echo "<td></td>";
echo "<td></td>";
$pageID = $row['pid'];
//The loop is left open
?>
<td>
<div class="buttons">
<form name="editPage" action="editPage.php" method="GET">
<input type="hidden" name="campaignID" value="<?php echo $campaignID ?>"/>
<input type="hidden" name="pageID" value="<?php echo $pageID ?>"/>
<button type="submit" name="editPage" value="Edit" class="blue" >
<img src="images/edit.png" width="20" height="20"></button>
</form>
</div>
</td>
<td>
<form name="deletePage" action="deletePage.php" method="POST">
<input type="hidden" name="pageID" value="<?php echo $pageID; ?>"/>
<div class="buttons">
<button type="submit" name="deletePage" value="Delete" class="negative">
<img src="images/delete_x.png" width="20" height="20"></button>
</div>
</form>
</td>
<?php
echo "</tr>\n";
$pcounter++;
$i++;
endwhile;
mysqli_free_result($presult);
?>
</table>
这是哪里$presult = LedDB::getInstance()->get_page_by_campaign_id($campaignID);
:
public function get_page_by_campaign_id($campaignID) {
$campaignID = $this->real_escape_string($campaignID);
return $this->query("SELECT pid,campaignid,message_text,message FROM pages WHERE campaignid =" . $campaignID );
}
每当我尝试将其包装在分页类中时,它要么返回一个 0 值,要么只是用sql_num_rows()
错误轰炸我的整个脚本......
这就是我认为 javascript 分页在这种情况下是最佳解决方案的原因。