我一直试图让我的数据库中的项目使用分页显示在我的应用程序上。然而,我遇到了一些绊脚石,其中包含一些我之前未遇到过的错误: -
未定义的索引:C:\ Users \ lenny \ Desktop \ TheVault \ vault.php中的页面 第14行
缺少FilmDataSet :: showFilms()的参数3,调用 第15行的C:\ Users \ lenny \ Desktop \ TheVault \ vault.php并在中定义 第26行的C:\ Users \ lenny \ Desktop \ TheVault \ Model \ FilmDataSet.php
未定义的变量:页面 第32行的C:\ Users \ lenny \ Desktop \ TheVault \ Model \ FilmDataSet.php
我在使用Netbeans作为我的IDE的应用程序上使用MVC,这些错误来自我的应用程序的这些部分: -
public function showFilms($UserID, $perPage, $page) {
//declare new film array
$film = array();
//SQL Query Selecting equivalent information to be displayed
// $sqlQuery = 'SELECT FilmID, Title, Director,YearofRelease, Genre, Image, MainActor, MainActor1, MainActor2, Synopsis FROM films WHERE User ="' . $UserID . '" LIMIT '.$perPage.' OFFSET '.(($page - 1)*$perPage).' ORDER BY Title DESC';
$sqlQuery = 'SELECT FilmID, Title, Director, YearofRelease, Genre, Image, MainActor, MainActor1, MainActor2, Synopsis FROM films WHERE User ="' . $UserID . '" ORDER BY Title DESC LIMIT ' . $perPage . ' OFFSET ' . (($page - 1) * $perPage) . '';
// prepare a PDO statement
$statement = $this->_dbHandle->prepare($sqlQuery);
// Execute PDO statement
$statement->execute();
// While loop fetches each row matching query
while ($row = $statement->fetch()) {
$film[] = array('FilmID' => $row['FilmID'],
'Title' => $row['Title'],
'User' => $UserID,
'Director' => $row['Director'],
'YearofRelease' => $row['YearofRelease'],
'Genre' => $row['Genre'],
'Image' => $row['Image'],
'MainActor' => $row['MainActor'],
'MainActor1' => $row['MainActor1'],
'MainActor2' => $row['MainActor2'],
'Synopsis' => $row['Synopsis']
);
}
//returning film array
return $film;
}
<div class="col-md-6">
<div id="FilmArea">
<!-- Count for Films -->
<?php
if (count($film)) {
?>
<br>
<!-- Displaying each entry using count of hidden list value of id of entry -->
<?php foreach ($film as $list): ?>
<!-- Panel Start -->
<div class="panel panel-info">
<!-- Panel Header -->
<div class="panel-heading">
<h3 class="panel-title" style="font-family: sans-serif; font-size: 20px; color: black; ">
<?= ( $list['Title']) ?> <small> Directed By : <?= ( $list['Director']) ?></small>
</h3>
</div>
<!-- Panel Body -->
<div class="panel-body">
<div id='dvdHolder'>
<?= ($list['Image'] <> "" ? "<img style='max-width:200px; max-height:200px;' src='Images/{$list['Image']}'/>" : "") ?>
</div>
<div id='dvdInfo'>
<p style='font-weight: bold;'> Year Released : <?= ( $list['YearofRelease']) ?></p>
<p style='font-weight: bold;'> Film Genre : <?= ($list['Genre'] ) ?></p>
<p style="font-weight: bold;"> Starring : <?= ($list['MainActor']) ?> , <?= ($list['MainActor1']) ?> , <?= ($list['MainActor2']) ?> </p>
<p style='font-weight: bold;'> Synopsis : <?= ($list['Synopsis'] ) ?></p>
</div>
</div>
</div>
<!-- End of Foreach Statement for Entry -->
<?php endforeach; ?>
<!-- Else show this message if user has no entries -->
<?php
}else {
?>
<p><b>No Films Added yet!</b></p>
<?php } ?>
<nav>
<ul class="pagination" style="position: relative; top: 507px; left: 250px;">
<li>
<a href="#" aria-label="Previous">
<span aria-hidden="true">«</span>
</a>
</li>
<li><a href="localhost:3000/films?page=1">1</a></li>
<li><a href="localhost:3000/films?page=2">2</a></li>
<li><a href="localhost:3000/films?page=3">3</a></li>
<li><a href="localhost:3000/films?page=4">4</a></li>
<li><a href="localhost:3000/films?page=5">5</a></li>
<li>
<a href="#" aria-label="Next">
<span aria-hidden="true">»</span>
</a>
</li>
</ul>
</nav>
</div>
<?php
session_start();
require_once('Model/UserDataSet.php');
require_once('Model/FilmDataSet.php');
$view = new stdClass();
$view->pageTitle = 'My Vault';
$aa = new FilmDataSet();
$film = array();
$page = htmlspecialchars($_GET['page']);
$film = $aa->showFilms($_SESSION['Email'], $page);
require_once('View/home.phtml');
我想如何纠正这个问题,因为我希望每页显示1个项目。我确实让它们出现在数据库中,但它们都是事先从数据库中显示出来的。
答案 0 :(得分:0)
你在showFilms()调用中缺少一个参数,它应该像
$film = $aa->showFilms($_SESSION['Email'], $item_per_page, $page);
并且您的$page
变量应为整数。
我建议您检查Datatables插件和Bootstrap table
编辑:如果您有大量数据(超过1000行),请考虑Pipelining data,它的效果非常好