所以现在这已经让我感到很难了,我得到了这个概念,我得到了教程,但是很多时候他们引用了数据的简单原始输出,而我的循环就像图库一样这样的
<?php
//external pages area
include_once('config/database.php');
include_once('object/chair.php');
//grabs info from the various pages.sql files
$database = new Database();
$conn = $database->getConnection();
$chair = new Chair($conn);
//connection made with sql file
$stmt = $chair->readAll();
//reading all the data in the sql file
$rows = $row[0];
$page_rows = 10;
$last = ceil($rows/$page_rows);
if($last < 1){
$last = 1;
}
$pagenum = 1;
if(isset($_GET['pn'])){
$pagenum = preg_replace('#[^0-9]#', '', $_GET['pn']);
}
if ($pagenum < 1) {
$pagenum = 1;
}else if ($pagenum > $last){
$pagenum = $last;
}
$limit = 'LIMIT ' .($pagenum - 1) * $page_rows .',' .$page_rows;
$sql = "SELECT id, THUMB, chair_name, PRICE FROM office_chairs $limit";
$textline1 = "pages (<b>$rows</b>)";
$textline2 = "Page <b>$pagenum</b> of <b>$last</b>";
$paginationCtrls = '';
if($last != 1){
if ($pagenum > 1) {
$previous = $pagenum - 1;
$paginationCtrls .= '<a href="'.$_SERVER['PHP_SELF'].'?pn='.$previous.'">Previous</a> ';
for($i = $pagenum-4; $i < $pagenum; $i++){
if($i > 0){
$paginationCtrls .= '<a href="'.$_SERVER['PHP_SELF'].'?pn='.$i.'">'.$i.'</a> ';
}
}
}
$paginationCtrls .= ''.$pagenum.' ';
for($i = $pagenum+1; $i <= $last; $i++){
$paginationCtrls .= '<a href="'.$_SERVER['PHP_SELF'].'?pn='.$i.'">'.$i.'</a> ';
if($i >= $pagenum+4){
break;
}
}
if ($pagenum != $last) {
$next = $pagenum + 1;
$paginationCtrls .= ' <a href="'.$_SERVER['PHP_SELF'].'?pn='.$next.'">Next</a> ';
}
}
然而,这是实际出现的代码。
while($row = $stmt->fetch(PDO::FETCH_ASSOC)){
明显的错误是$ rows等于未定义的元素但是我不确定它应该是什么相等,它不喜欢等于stmt var的任何变体。
<div class="product_box" >
<a href="chair-details.php?detailsid=<?php echo $row['ID'];?>">
<img src="img/<?php echo $row['THUMB']; ?>" alt="chair_image">
</a>
<div class="productdetailwrapper">
<div class="productleft">
<div class="productnamebanner">
<p class="productName" ><?php echo $row['chair_name'];?></p>
</div>
<em class="d-price"><?php echo $row['PRICE'];?></em>
<span class="ratings">
Not rated
</span>
</div>
<div class="ProductActionAdd" style="display:;">
<a href="chair-details.php?detailsid=<?php echo $row['ID'];?>" class="btn">More Info!</a>
</div>
</div>
</div>
<?php
}
?>