本文整理汇总了PHP中Pager::get_offset方法的典型用法代码示例。如果您正苦于以下问题:PHP Pager::get_offset方法的具体用法?PHP Pager::get_offset怎么用?PHP Pager::get_offset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pager
的用法示例。
在下文中一共展示了Pager::get_offset方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: search
function search()
{
global $display;
$catid = (int) Url::get('catid', 0);
$total = (int) Url::get('total', 0);
$page = (int) Url::get('page', 0);
$tt = (int) Url::get('tt', 0);
$keywords = Url::get('keywords');
require "./includes/sphinxapi.class.php";
EClassApi::getCats();
foreach (CGlobal::$allCategories as $value) {
if ($value['parent_id'] == 0) {
$cat_list[$value['id']] = $value['brief_name'];
}
}
$category = $this->getCategory($keywords);
foreach ($category as $row) {
$row['brief_name'] = isset($cat_list[$row['level_1_category_id']]) && $cat_list[$row['level_1_category_id']] ? $cat_list[$row['level_1_category_id']] : "Khác";
$listCat[$row['level_1_category_id']] = array("level_1_category_id" => $row["level_1_category_id"], "brief_name" => $row['brief_name'], "count_ad" => $row['@count']);
}
$catActive = '';
$total_cat = 0;
if ($listCat) {
$catActive = $listCat[$catid]['brief_name'];
$total_cat = count($listCat);
}
$i = 0;
$allrecord = 0;
$otherCat = '';
$cat_content = "";
foreach ($listCat as $cat) {
$allrecord = $allrecord + $cat['count_ad'];
}
$display->add("cat_content", $cat_content);
$display->add("CatActiveId", $catid);
$display->add("catActive", $catActive);
$display->add("listCat", $listCat);
$display->add("allrecord", $allrecord);
$display->add("total_cat", $total_cat);
$pager = new Pager();
$limit = SEARCH_LIMIT;
$pager->type = "search";
$pager->catid = $catid;
$pager->total = $total;
$pager->limit = $limit;
$pager->page_param = 'page';
$pager->page = $page;
$offset = $pager->get_offset();
$limit_from = $pager->limit_from();
$limit_to = $pager->limit_to();
//Sphinx search by Nova
$q = $keywords;
//$mode = SPH_MATCH_ALL;
$mode = SPH_MATCH_EXTENDED2;
//Init config
$host = SPHINX_SERVER;
$port = SPHINX_PORT;
$index = 'enbac';
$filtervals = array();
//$ranker = SPH_RANK_PROXIMITY_BM25;
$ranker = SPH_RANK_WORDCOUNT;
$cl = new SphinxClient();
$cl->SetServer($host, $port);
$cl->SetConnectTimeout(1);
$cl->SetWeights(array(100, 1));
$cl->SetMatchMode($mode);
$cl->SetFilter('level_1_category_id', array($catid));
$cl->SetFilter('status', array('1'));
$cl->SetFieldWeights(array('user_name' => 10000, 'name' => 1000, 'description' => 1));
//$cl->SetSortMode( SPH_SORT_EXTENDED, 'up_time DESC' );
//$cl->SetSortMode( SPH_SORT_RELEVANCE);//Sort theo kq chính xác nhất
//$cl->SetSortMode ( SPH_SORT_EXPR, "@weight + ( user_karma + ln(pageviews) )*0.1");
$cl->SetSortMode(SPH_SORT_EXPR, "@weight");
//Sort theo trọng số
$cl->SetLimits($offset, $limit, 10000);
$cl->SetRankingMode($ranker);
$cl->SetArrayResult(true);
$res = $cl->Query($q, $index);
if ($res && isset($res["matches"])) {
if (is_array($res["matches"])) {
foreach ($res["matches"] as $results) {
$list_item_id[] = $results['id'];
}
}
$comma_separated = join(",", $list_item_id);
}
if ($total) {
if ($limit_to > $total) {
$limit_to = $total;
}
$comma_separated = join(",", $list_item_id);
if ($comma_separated) {
//$sql = "SELECT id,name,up_time,price,user_id,user_name, level_1_category_id,category_id,description,original_image_url, img_server FROM item WHERE id IN ($comma_separated) AND status=1 ORDER BY up_time DESC";
$sql = "SELECT id,name,up_time,price,user_id,user_name, level_1_category_id,category_id,description,original_image_url, img_server FROM item WHERE id IN ({$comma_separated}) AND status=1 ORDER BY find_in_set(id,'{$comma_separated}')";
$search_result = DB::query($sql);
$pager->total = $total;
$paging = $pager->page_link();
}
}
$item_array = array();
//.........这里部分代码省略.........
示例2: array
function draw2()
{
$keywords = AZLib::getParam('keywords');
$total_item = 0;
$search_result = false;
$items = array();
$paging = '';
$cmd = '';
$cat_search_id = 0;
$item_array = array();
$listCat = array();
if ($keywords) {
//AZLib::getCats();
require "./includes/sphinxapi.class.php";
foreach (CGlobal::$allCategories as $value) {
if ($value['parent_id'] == 0) {
$cat_list[$value['id']] = $value['brief_name'];
}
}
$category = $this->getTotalPerCategory($keywords);
foreach ($category as $row) {
$row['brief_name'] = isset($cat_list[$row['level_1_catid']]) && $cat_list[$row['level_1_catid']] ? $cat_list[$row['level_1_catid']] : "Khác";
$listCat[$row['level_1_catid']] = array("level_1_catid" => $row["level_1_catid"], "brief_name" => $row['brief_name'], "count_ad" => $row['@count']);
}
$total = 0;
$catid = 0;
$catActive = '';
$total_cat = 0;
if ($listCat) {
$first_val = array_slice($listCat, 0, 1);
$total = $first_val[0]['count_ad'];
$catid = $first_val[0]['level_1_catid'];
$catActive = $first_val[0]['brief_name'];
$total_cat = count($listCat);
}
$i = 0;
$allrecord = 0;
$otherCat = '';
$cat_content = "";
foreach ($listCat as $cat) {
if ($i < 3) {
$active = $i == 0 ? "class=\"active\"" : "";
$cat_content .= "<li id=\"tab_{$i}\" {$active} onclick=\"javascript:acive_tab_cat(this);\"><a href=\"javascript:void(0);\" onclick=\"javascript:search_cat({$cat['level_1_catid']},{$cat['count_ad']},1,0);\"><span id=\"kby_{$cat['level_1_catid']}\">" . $cat['brief_name'] . " <font style=\"color: #5a7e92;font-weight: normal;\">(" . $cat['count_ad'] . ")</font></span></a></li>";
} else {
$otherCat .= "<div class=\"other\"><a href=\"javascript:void(0);\" onclick=\"javascript:search_cat({$cat['level_1_catid']},{$cat['count_ad']},1,0);acive_tab_cat(this);\" id=\"tab_{$i}\"><span id=\"kby_{$cat['level_1_catid']}\">" . $cat['brief_name'] . " <font style=\"color: #5a7e92;font-weight: normal;\">(" . $cat['count_ad'] . ")</font></span></a></div>";
}
$i++;
$allrecord = $allrecord + $cat['count_ad'];
}
$display->add("cat_content", $cat_content);
$display->add("CatActiveId", $catid);
$display->add("catActive", $catActive);
$display->add("listCat", $listCat);
$display->add("allrecord", $allrecord);
$display->add("otherCat", str_replace(array(chr(13), chr(10)), "", $otherCat));
$display->add("total_cat", $total_cat);
//Init for sphinx search paging
$pager = new Pager();
//config
$limit = SEARCH_LIMIT;
$pager->type = "search";
$pager->catid = $catid;
$pager->total = $total;
$pager->limit = $limit;
$pager->page_param = 'page';
$pager->page = 1;
$offset = $pager->get_offset();
$limit_from = $pager->limit_from();
$limit_to = $pager->limit_to();
//Sphinx search by Nova
$q = $keywords;
$mode = SPH_MATCH_EXTENDED2;
//Init config
$host = SPHINX_SERVER;
$port = SPHINX_PORT;
//$index = SPHINX_INDEX;
$index = "enbac delta";
$filtervals = array();
$ranker = SPH_RANK_WORDCOUNT;
$cl = new SphinxClient();
$cl->SetServer($host, $port);
$cl->SetConnectTimeout(1);
$cl->SetWeights(array(100, 1));
$cl->SetMatchMode($mode);
//filter
if ($catid) {
$cl->SetFilter('level_1_catid', array($catid));
}
$cl->SetFilter('status', array('1'));
$cl->SetFieldWeights(array('user_name' => 10000, 'name' => 1000, 'description' => 1));
//$cl->SetSortMode( SPH_SORT_EXTENDED, 'up_time DESC' );
//$cl->SetSortMode( SPH_SORT_RELEVANCE);//Sort theo kq chính xác nhất
//$cl->SetSortMode ( SPH_SORT_EXPR, "@weight + ( user_karma + ln(pageviews) )*0.1");
$cl->SetSortMode(SPH_SORT_EXPR, "@weight");
//Sort theo trọng số
//SPH_RANK_WORDCOUNT
//SPH_MATCH_EXTENDED2
//end filter
$cl->SetLimits($offset, $limit, 10000);
$cl->SetRankingMode($ranker);
//.........这里部分代码省略.........