你会如何分页?数据由下面的“getInstance”查询调用,然后显示一些称为“页面”的记录,这些记录列在动态表中。
我希望每个查询只能显示 10 个“页面”并将它们分页
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="std">
<?php
$counter = 1;
$userID = PageDB::getInstance()->get_user_id_by_name($_SESSION['user']);
$result = PageDB::getInstance()->get_pages_by_campaign_id($campaignID);
$i=0;
while ($row = mysqli_fetch_array($result)):
$style = "";
if($i%2==0)
{
$style = ' style="background-color: #EFEFEF"';
}
echo "<tr".$style.">";
echo "<td> </td>";
echo "<td></td>";
//The loop is left open
?>
<td>
<form style="display:none;"></form>
<div id="Pagination" class="pagination"> </div>
<div id="Searchresult"> </div>
<form name="editPage" action="editPage.php" method="GET">
<input type="hidden" name="pageID" value="<?php echo $pageID = $row['pid']; ?>" />
<input type="submit" name="editPage" value="<?php echo "Page " . $counter; ?>" style="background:none;border:none; cursor:pointer"/>
</form>
</td>
<td>
<form name="deletePage" action="deletePage.php" method="POST">
<input type="hidden" name="pageID" value="<?php echo $pageID = $row['pid']?>"/>
<input type="submit" name="deletePage" value="Delete" onclick = "javascript: return confirm('Delete Page <?php echo $counter ?> ?');"/>
</form>
</td>
<?php
$pageID = $row['pid'];
$counter++;
$i++;
echo "</tr>\n";
endwhile;
mysqli_free_result($result);
?>
</table>
查询引用了这两个调用用户 ID 的公共函数,以便从数据库调用相关页面:
public function get_user_id_by_name($name) {
$name = $this->real_escape_string($name);
$user = $this->query("SELECT id FROM users WHERE name = '" . $name . "'");
if ($user->num_rows > 0){
$row = $user->fetch_row();
return $row[0];
} else
return null;
}
public function get_pages_by_campaign_id($campaignID) {
$campaignID = $this->real_escape_string($campaignID);
return $this->query("SELECT pid , campaignid FROM pages , campaigns WHERE campaignid = campaigns.id");
}
谁能看到解决方案?谢谢!