PHP分页内容

时间:2015-03-08 10:02:04

标签: php pagination

我有一个内容列表,我会有一个分页。到目前为止,我能够正确计算我们的内容,然后我们有3个内容,并且每页最多强加2个应用程序,在我的索引中显示了转到下一页的链接。

但是,不幸的是,始终显示相同的内容。例如:

http://i62.tinypic.com/156skjo.png

http://i60.tinypic.com/30xcy1l.png

但是,我粘贴了当前的代码,希望你能帮助我。谢谢

<?php require_once 'app/init.php'; ?>
<?php echo View::make('header')->render() ?>
<div class="row">
<!-- START MAIN GRID -->
<?php

// Create a variable imposed where the number of records
// To display on each page
$x_pag = 2;

// Retrieve the current page number.
// Usually you use a querystring
$pag = isset($_GET['pag']) ? $_GET['pag'] : 1;

// Check if $pag is valued and if numeric
// ... Otherwise I assign a value of 1
if (!$pag || !is_numeric($pag)) $pag = 1;

    $quest = DB::table('questions')
        ->count();

// Using a simple mathematical operation define the total number of pages
$all_pages = ceil($quest / $x_pag);

// Calculation of which record start
$first = ($pag - 1) * $x_pag;

    $questions = DB::table('questions')
        ->orderBy('id', 'desc')
        ->take($x_pag)
        ->get();

foreach ($questions as $question): 
$user = User::find($question->user_id);

        ?>
        <div class="col-md-4 col-lg-4">
        <div class="main-grid">
        <div class="profile-inner img-responsive" style="background-image: url('images/<?php echo $question->h_image; ?>');border-radius: 10px 10px 0px 0px;">
        <a href="profile.php?u=<?php echo $question->user_id; ?>"><img src="<?php echo $user->avatar; ?>" class="small-thumb" ></a> 
            </div>
            <div class="description">
            <h5><strong><?php echo $question->user_name; ?></strong>
            <?php if (Auth::check() && Auth::user()->id != $question->user_id): ?>
            <?php $contact = Contact::find(Auth::user()->id, $question->user_id); ?>
            <?php if (!empty($contact) && !empty($contact->accepted)): ?>
                        ( <a href="javascript:EasyLogin.removeContact(<?php echo $question->user_id ?>)" data-contact-id="<?php echo $question->user_id ?>"><?php _e('main.remove_contact') ?></a> )
                    <?php elseif (!empty($contact)): ?>
                        ( <a href="javascript:EasyLogin.removeContact(<?php echo $question->user_id ?>)" data-contact-id="<?php echo $question->user_id ?>" ><?php _e('main.cancel_contact') ?></a> )
                    <?php else: ?>
                        ( <a href="javascript:EasyLogin.addContact(<?php echo $question->user_id ?>)" data-contact-id="<?php echo $question->user_id ?>"><?php _e('main.add_contact') ?></a> )
                <?php endif ?>
                <?php endif ?>
                </h5>
                <h3><?php echo $question->h_title; ?>?</h3>
                <hr />
                <a href="help.php?id=<?php echo $question->id; ?>" class="btn btn-info btn-block">Help + </a>
                </div>
                </div>
                </div>
                <?php endforeach; ?>
    <!-- MAIN GRID END -->   
</div>

<?php 
// If the total pages are more than 1 ...
// Mold the link to go back and forth between different pages!
if ($all_pages > 1){
    if ($pag > 1){
    echo "<a href=\"" . $_SERVER['PHP_SELF'] . "?pag=" . ($pag - 1) . "\">";
    echo "Back</a>&nbsp;";
    } 
    if ($all_pages > $pag){
        echo "<a href=\"" . $_SERVER['PHP_SELF'] . "?pag=" . ($pag + 1) . "\">";
        echo "Next</a>";
    } 
}
?>  

<?php echo View::make('footer')->render() ?>

0 个答案:

没有答案