如何使用PHP使分页与引导程序一起工作


How do I get pagination to work with bootstrap using PHP?

我一直在尝试使用分页将数据库中的项目显示在应用程序上。然而,我遇到了一些以前从未遇到过的错误,这些错误是:-

  • 未定义的索引:C:''Users''lenny''Desktop''TheVault''vault.php中的页面第14行

  • FilmDataSet::showFilms()缺少参数3,在中调用C: ''Users''lenny''Desktop''TheVault''vault.php,位于第15行,在C: 第26行的''Users''lenny''Desktop''TheVault''Model''FilmDataSet.php

  • 未定义的变量:中的页面C: 第32行上的''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">&laquo;</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">&raquo;</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');

任何关于如何纠正这一点的想法,因为我希望每页显示一个项目。我确实从数据库中看到了它们,但它们都是事先从数据库中出现的。

showFilms()调用中缺少一个参数,它应该像

$film = $aa->showFilms($_SESSION['Email'], $item_per_page, $page);

并且您的CCD_ 1变量应该是一个整数。

我建议你检查数据表插件和引导表

编辑:如果你有很多数据(超过1000行),考虑流水线数据,它工作得很好