2012-09-14 51 views
0

我添加類似於「顯示11條目中的1到10」「顯示11條目的11到11」到搜索結果頁面。顯示x到y的z條目

$listing_search.listings_per_page = 10 
$listing_search.current_page = 2 
$listings_number = 11 

我無法得到正確的公式。 。請分享一些光。

[[Showing ]] {if $listing_search.current_page == 1}1{else}{$listing_search.listings_per_page+1} {/if} 
[[ to ]] {$listing_search.listings_per_page}[[ of ]] {$listings_number} {if $listings_number == 1}[[ Job]]{else}[[ Jobs]]{/if} 

對頁面3,4等的任何建議?那是同一個公式嗎?

我只能測試11個條目。這是我編輯的。

{assign var="current_page" value = $listing_search.current_page} 
{assign var="listings_per_page" value = $listing_search.listings_per_page} 
{math assign="first_page" equation="(cp - 1) * lpp + 1" cp=$current_page lpp=$listings_per_page } 
{math assign="last_page" equation="(cp * lpp)" cp=$current_page lpp=$listings_per_page } 

<div class="" id="DataTables_Table_1_info">[[Showing ]] {if $first_page}{$first_page} {else}[[1]]{/if} [[to]] {if $last_page <= $listings_number}{$last_page}{else} {$listings_number}{/if} 
[[of]] {$listings_number} {if $listings_number == 1}[[ Job]]{else}[[ Jobs]]{/if}</div> 

回答

0
  • 當前頁的開始:(current_page-1)*listings_per_page +1
  • 當前頁面的結束:current_page*listings_per_pagelistings_number(取小者)
0

的公式是這樣的:

listings_per_page = 10 
current_page = 2 
listings_number = 11 (I would call this total_listings or something like that) 

first_listing = listings_per_page * (current_page - 1) + 1 
max_last_listing = (listings_per_page * current_Page) 
last_listing = (max_last_listing > total_listings) ? total_listings : max_last_listing 

,將使first_listing == 11 和最後上市的將是20或最大,取其較小者。

相關問題