简体   繁体   English

如何使用PHP使用引导程序进行分页?

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

I have been attempting to get my items in the database to show on my application using pagination. 我一直试图让我的数据库中的项目使用分页显示在我的应用程序上。 However I have hit a stumbling block with some errors that I haven't come across before which are :- 然而,我遇到了一些绊脚石,其中包含一些我之前未遇到过的错误: -

  • Undefined index: page in C:\\Users\\lenny\\Desktop\\TheVault\\vault.php on line 14 未定义的索引:第14行的C:\\ Users \\ lenny \\ Desktop \\ TheVault \\ vault.php中的页面

  • Missing argument 3 for FilmDataSet::showFilms(), called in C:\\Users\\lenny\\Desktop\\TheVault\\vault.php on line 15 and defined in C:\\Users\\lenny\\Desktop\\TheVault\\Model\\FilmDataSet.php on line 26 缺少FilmDataSet :: showFilms()的参数3,在第15行的C:\\ Users \\ lenny \\ Desktop \\ TheVault \\ vault.php中调用,并在C:\\ Users \\ lenny \\ Desktop \\ TheVault \\ Model \\ FilmDataSet.php中定义第26行

  • Undefined variable: page in C:\\Users\\lenny\\Desktop\\TheVault\\Model\\FilmDataSet.php on line 32 未定义的变量:第32行的C:\\ Users \\ lenny \\ Desktop \\ TheVault \\ Model \\ FilmDataSet.php中的页面

I am using MVC on my application using Netbeans as my IDE, these errors are from these sections of my application which are :- 我在使用Netbeans作为我的IDE的应用程序上使用MVC,这些错误来自我的应用程序的这些部分: -

Model 模型

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;
}

View 视图

<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>

Controller 调节器

<?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');

Any Ideas of how I can rectify this as I want 1 item to show up per page. 任何关于我如何纠正这个的想法,因为我希望每页显示1个项目。 I did get them appearing from the database however they were all just showing up from the database beforehand. 我确实让它们出现在数据库中,但它们都是事先从数据库中显示出来的。

You are missing a parameter in your showFilms() call, it should be like 你在showFilms()调用中缺少一个参数,它应该是这样的

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

and your $page variable should be an integer. 你的$page变量应该是一个整数。

I suggest you to check both Datatables plugin and Bootstrap table 我建议你检查Datatables插件和Bootstrap表

EDIT: if you have lots of data (more than 1000 rows), consider Pipelining data , it works very good 编辑:如果您有大量数据(超过1000行),请考虑管道数据 ,它非常好用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM