Php 页码不起作用
我目前正在尝试在我的表中实现分页,但是,每当我单击页面时,它们都不会显示下一页,即使地址栏上的链接清楚地显示page=2、page=3等。我想知道我的代码是否有任何错误。多谢各位Php 页码不起作用,php,pagination,Php,Pagination,我目前正在尝试在我的表中实现分页,但是,每当我单击页面时,它们都不会显示下一页,即使地址栏上的链接清楚地显示page=2、page=3等。我想知道我的代码是否有任何错误。多谢各位 $totalPerPage = 20; $size= "50"; $sql = ("SELECT DISTINCT * FROM shoe s INNER JOIN shoelace sc ON s.cod = sc.cod WHERE s.sh
$totalPerPage = 20;
$size= "50";
$sql = ("SELECT DISTINCT * FROM shoe s
INNER JOIN shoelace sc ON s.cod = sc.cod
WHERE s.shoefit =?");
$stmt = $db->prepare($sql);
$stmt->execute([$size]);
$numberofResults = $stmt->rowCount();
$numberOfPages = ceil($numberofResults/$totalPerPage);
if(isset($_GET['page'])){
$page = $_GET['page'];
}else{
$page = 1;
}
$thePageFormula = ($page-1)*$totalPerPage;
$query = ("SELECT DISTINCT * FROM shoe s
INNER JOIN w_shoelace sc ON s.cod = sc.cod
WHERE s.shoefit =?
LIMIT $thePageFormula,$totalPerPage");
$stmt2 = $db->prepare($query);
$stmt2->execute([$size]);
while($row = $stmt2->fetch(PDO::FETCH_ASSOC)){
//echos infromation in table form
echo "<table><tr onclick='javascript:showRow(this);'><td>"
. $row['shoename'] . "</td><td>"
. utf8_encode($row['shoecolor']) . "</td><td>"
<img src='data:image/jpeg;base64,".base64_encode($row['shoeimg'])."'width='50' height='30'/></td><tr>";
echo "</table>";
}
for ($page=1; $page <= $numberOfPages ; $page++){
echo "<div class='pagination'>
<a href='?page=" . $page . "'>" . $page . "</a>
</div>";
}
$totalPerPage=20;
$size=“50”;
$sql=(“从鞋中选择不同的*
s.cod上的内连接鞋带sc=sc.cod
其中s.shoefit=?”;
$stmt=$db->prepare($sql);
$stmt->execute([$size]);
$numberofResults=$stmt->rowCount();
$numberOfPages=ceil($numberofResults/$totalPerPage);
如果(isset($_GET['page'])){
$page=$_GET['page'];
}否则{
$page=1;
}
$thepage公式=($page-1)*$total每页;
$query=(“从鞋子中选择不同的*
s.cod=sc.cod上带鞋带sc的内部连接
其中s.shoefit=?
限制$thePageFormula,$totalPerPage”);
$stmt2=$db->prepare($query);
$stmt2->execute([$size]);
而($row=$stmt2->fetch(PDO::fetch_ASSOC)){
//表格形式的回声信息
回声“”
.$row['shoename']
.utf8_编码($row['shoecolor'])”
";
回声“;
}
对于($page=1;$page我认为问题出在这个SQL查询中
SELECT DISTINCT * FROM shoe s
INNER JOIN w_shoelace sc ON s.cod = sc.cod
WHERE s.shoefit =?
LIMIT $thePageFormula,$totalPerPage
对于分页,您必须始终维护SQL查询的offset值,这意味着它应该从哪里开始从数据库获取数据
SELECT DISTINCT * FROM shoe s
INNER JOIN w_shoelace sc ON s.cod = sc.cod
WHERE s.shoefit =?
LIMIT *limit_to_show_per_page*, *offset*
如果您开始从数据库中提取数据,并且第一页的限制为10,则偏移量值必须为0,如果转到第二页,则每页的限制将固定为10,并且偏移量将从0更改为10,依此类推。
希望你能明白这一点。每页显示的限制和偏移量应该是我创建的变量吗?是的,你需要维护一个变量来跟踪偏移量值,所以我更改了限制变量,但现在没有显示数据。选择DISTINCT*FROM shoe的内部连接w_鞋带sc ON s.cod=sc.cod其中s.shoefit=?LIMIT$totalPerPage,$thepage公式;或者我应该这样做吗?在s.cod=sc.cod上选择DISTINCT*与鞋的内部连接w_鞋带sc,其中s.shoefit=?LIMIT$totalPerPage OFFSET$thepage公式;