簡體   English   中英

分頁-如何顯示每頁結果?

[英]Pagination-How to display the results per page?

我已經完成了腳本編寫工作,每頁僅顯示40個結果,但是我無法讓用戶在下一頁中看到其余結果。我正在使用Curl操作獲取數據。

我沒有發布代碼,因為它太長了。 請檢查此鏈接

那么,如何在下一頁顯示其余結果?

對不起,如果我的問題有任何錯誤。 謝謝

 if($search_results['api']['status']=="Success")
{

$inc= 1;
$ert = $search_results['result']['Properties'];

if($sortby=='Name'){


foreach ($ert as $name) {
    $names[] = $name['name'];

}
array_multisort($names, SORT_ASC, $ert);
}

if($sortby=='OverallRating'){


foreach ($ert as $name) {
    $names[] = $name['avgRating'];

}
array_multisort($names, SORT_NUMERIC,SORT_DESC, $ert);
}

if($sortby=='Price'){


foreach ($ert as $name) {
    $tuti = array_keys($name['bedPrices']['cheapestPrivate']);

    // echo $name['bedPrices']['cheapestPrivate'][$tuti[0]];
    $names[] = $name['bedPrices']['cheapestPrivate'][$tuti[0]];

}
array_multisort($names, SORT_NUMERIC,SORT_ASC, $ert);
}



// var_dump($ert['bedPrices']);




                    foreach($ert as $hostels)
                    {
if($inc>$page_limit){
    continue;
}

                        if(!((int)$hostels['avgRating'] >= (int)$min_rate && (int)$hostels['avgRating'] <= (int)$max_rate))
                            continue;
                        if(!((int)$hostels['bedPrices']['cheapestPrivate']['USD'] >= (int)$min_pricing && (int)$hostels['bedPrices']['cheapestPrivate']['USD'] <= (int)$max_pricing))
                            continue;
                        if(!(in_array($hostels['type'],$properties_zan_array)))
                            continue;
                            // var_dump($hostels);
                            $arry_hostel = (array) $hostels;
                            foreach ($arry_hostel['roomTypes'] as $hkey => $hvalue) {


                            if(arrayInString($roomtype_zan_array,$hvalue['description'])){



                            echo $hostels[0]['ResultCount'];

                        ?>
                        <?php $propNum1 =$hostels['number']; ?>
                        <div class="search_result">
                <div class="se_img">

                    <div class="top_rated">Top Rated</div> 
                    <form action='hostel-details' method='GET'>
                            <input type='hidden' name='hname' value='<?php echo $hostels['name'];?>'>
                                <input type='hidden' name='city' value='<?php echo "$citi" ;?>'>
                                    <input type='hidden' name='date_st' value='<?php echo "$startdate" ;?>'>
                                        <input type='hidden' name='date_end' value='<?php echo "$enddate" ;?>'>
                                            <input type='hidden' name='num' value='<?php echo "$Num" ;?>'>
                                            <input type='hidden' name='propnum' value='<?php echo "$propNum1" ;?>'>
                                                    <input type='hidden' name='guestnum' value='<?php echo $guests?>'>

                    <a href='#' onclick='this.parentNode.submit()'>
                        <img src="<?php echo $hostels['images']['0']['url'] ?>" height="80" width="120" class="search_img" title="<?php echo $hostels['name']; ?>" />
                    </a>
                    <span><?php echo $hostels['type']; ?></span>
                </div>
                <div class="se_detail">



                    <form action='hostel-details' method='GET'>
                            <input type='hidden' name='hname' value='<?php echo $hostels['name'];?>'>
                                <input type='hidden' name='city' value='<?php echo "$citi" ;?>'>
                                    <input type='hidden' name='date_st' value='<?php echo "$startdate" ;?>'>
                                        <input type='hidden' name='date_end' value='<?php echo "$enddate" ;?>'>
                                            <input type='hidden' name='num' value='<?php echo "$Num" ;?>'>
                                            <input type='hidden' name='propnum' value='<?php echo "$propNum1" ;?>'>
                                                    <input type='hidden' name='guestnum' value='<?php echo $guests?>'>
                    <!--<a href="#" onclick='this.parentNode.submit()' style="font-size: 14px;">-->
                    <a href="#"><button style="border: none;"><font style="color:blue">
                    <h2 class="se_title" ><?php echo $hostels['name']; ?></h2>
                    <!--</a> 
                    </form>-->
                    <div class="se_meta"><?php echo $hostels['address1'].", ".$hostels['address2'] ?></div></font></button></a></form>
                        <?php $propNum =$hostels['number']; ?>
                    <!-- <div class="se_warning">Minimum stay of 4 nights for your selected dates</div> -->
                    <div class="se_desc"><?php echo substr($hostels['shortDescription'],0,80)."..." ?> <!-- <a href="#">More Info</a> -->



                <form action='hostel-details' method='GET'>

                            <input type='hidden' name='hname' value='<?php echo $hostels['name'];?>'>
                                    <input type='hidden' name='city' value='<?php echo "$citi" ;?>'>


                                    <input type='hidden' name='date_st' value='<?php echo "$startdate" ;?>'>
                                        <input type='hidden' name='date_end' value='<?php echo "$enddate" ;?>'>
                                            <input type='hidden' name='num' value='<?php echo "$Num" ;?>'>
                                            <input type='hidden' name='propnum' value='<?php echo "$propNum" ;?>'>
                                                    <input type='hidden' name='guestnum' value='<?php echo $guests?>'>
            <!--            <input type='hidden' name='search_res' value='<?php echo base64_encode(serialize($hostels)); ?>' /> -->
                        <a href='#' onclick='this.parentNode.submit()'>More Info</a>
                </form>

                    </div>

                    <div class="se_review">

                        <?php  if($hostels['avgRating']==0)
                                {
                                    echo '<span style="font-weight:bold;float:left;">No Rating</span>';
                                }
                                else
                                {
                                    echo '<div class="se_per">'.$hostels['avgRating']."%".'</div>';
                                }
                        ?>

                        <a href="#">
                                <?php if($hostels['starRating']!='None' &&$hostels['starRating']!=0)
                                        {
                                            echo $hostels['starRating']." Total Reviews";
                                        }
                                    else
                                        echo '<span style="font-weight:bold;"> No Reviews</span>';
                                ?>
                        </a>
                        <div style="clear:both;"></div>
                    </div>

                    <div class="se_compare">
                        <!--<input type="checkbox" class="comp_check"/>
                         <label class="cmp">Compare (0 of 5)</label> -->
                    </div>
                </div>

                <div class="se_price">
                        <?php if(!empty($hostels['bedPrices']))
                            {
                                if(isset($hostels['bedPrices']['cheapestDorm']))
                                {
                                    foreach($hostels['bedPrices']['cheapestDorm'] as $currency=>$price){
                                        echo    '<div class="do_form">Dorms From</div>';
                                        echo    '<div class="do_price">'.$currency.$price.'</div>';
                                    }
                                }
                                if(isset($hostels['bedPrices']['cheapestPrivate']))
                                {
                                    foreach($hostels['bedPrices']['cheapestPrivate'] as $currency=>$price)
                                    {
                                        echo '<div class="do_form">Privates From</div>
                                                <div class="do_price">'.$currency.$price.'</div>';
                                    }
                                }
                            }
                        ?>

                        <div class="book_btn">
                        <form action='hostel-details' method='GET'>

                            <input type='hidden' name='hname' value='<?php echo $hostels['name'];?>'>
                                    <input type='hidden' name='city' value='<?php echo "$citi" ;?>'>


                                    <input type='hidden' name='date_st' value='<?php echo "$startdate" ;?>'>
                                        <input type='hidden' name='date_end' value='<?php echo "$enddate" ;?>'>
                                            <input type='hidden' name='num' value='<?php echo "$Num" ;?>'>
                                            <input type='hidden' name='propnum' value='<?php echo "$propNum" ;?>'>
                                                    <input type='hidden' name='guestnum' value='<?php echo $guests?>'>
            <!--            <input type='hidden' name='search_res' value='<?php echo base64_encode(serialize($hostels)); ?>' />-->

                        <a href='#' onclick='this.parentNode.submit()'>Book Now</a>
                        </div>
                </div>
                <div style="clear:both;"></div>
            </div>

                        <?php
break;
                            }
                }

                $inc++;
                }
 echo $inc;


            }

嘗試修改此php代碼:

// set the number of records to display per page.

$display = 10;

// check if the number of pages has been determined.

if(isset($_GET['$p']) && is_numeric($_GET['$p'])) {
$pages = $_GET['$p'];
}
else {
$q = "SELECT COUNT(user_id) FROM users";
$r = mysqli_query($dbc,$q);
$row = mysqli_fetch_array($r,MYSQLI_NUM);
$records = $row[0];

// count the number of pages

if($records > $display) { // more than 10 records = 1 page
    $pages = ceil($records/$display);
}
else {
    $pages = 1;
}
} // end of if is set $page

// Determine where in the database to start returning results...eg. page 1 , 2 or 3

if(isset($_GET['s']) && is_numeric($_GET['s'])) {
$start = $_GET['s'];
}
else {
$start = 0;
}

// section for displaying links to other pages in table if necessary

if($pages > 1) {
echo '<br/><p>';
$current_page = ($start/$display) + 1;

// if it not the first page make a PREVIOUS button
if($current_page != 1) {
    echo '<a href="view_users.php?s='.($start -       $display).'&p='.$pages.'&sort='.$sort.'">Previous</a> ';
}
// make all the numbered pages inside (if current page)

    for ($i = 1; $i <= $pages; $i++) {
        if ($i != $current_page) {
            echo '<a href="view_users.php?s='.(($display*($i - 1))).'&p='.$pages.'&sort='.$sort.'">'.$i.'</a> ';
            }
            else {
                echo $i.' ';
            }
    }
// make the NEXT link if not the last page

if($current_page != $pages) {
    echo '<a href="view_users.php?s='.($start + $display).'&p='.$pages.'&sort='.$sort.'">Next</a>';
}
echo '</p>';
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM