Постраничная навигация
1.
YouMobe (11.04.2014 / 08:40)
не могу сделать навигацию по такому шаблону <<< 1,2,3,
4,5,6 >>>
private function get_navigation_menu($app)
{
$app->set("menu", $app->get('DB')->exec("SELECT * FROM `categories`"));
$app->set("static_page", $app->get('DB')->exec("SELECT * FROM `static_page`"));
}
public function pagination($table='posts')
{
$current_page = $this->app->get('PARAMS.page')-1;
#переменная news - находится в конфиге -_- news = количество новостей на страницу.
$next_page = (1+$current_page) * $this->app->get("news");
$prev_page = ($current_page-1) * $this->app->get("news");
if($table == 'posts')
{
$category_id = $this->app->get('PARAMS.id_category');
if($this->app->get("admin_panel"))
{
$query = "SELECT `id` FROM `posts` ORDER BY `id` desc LIMIT ?,?";
$query_params['inc'] = array(
1 => $next_page,
2 => $this->app->get('news')
);
$query_params['dec'] = array(
1 => $prev_page,
2 => $this->app->get('news')
);
}
else
{
$query = "SELECT `id` FROM `posts` WHERE `category_id` = ? ORDER BY `id` desc LIMIT ?,?";
#Только для удобочитаемости, я не про форматирование текста =_=
$query_params['inc'] = array(
1 => $this->app->get('PARAMS.id_category'),
2 => $next_page,
3 => $this->app->get('news')
);
$query_params['dec'] = array(
1 => $this->app->get('PARAMS.id_category'),
2 => $prev_page,
3 => $this->app->get('news')
);
}
}
else
{
$category_id = $table;
$query = "SELECT `id` FROM $table ORDER BY `id` desc LIMIT ?,?";
$query_params['inc'] = array(
1 => $next_page,
2 => $this->app->get('news')
);
$query_params['dec'] = array(
1 => $prev_page,
2 => $this->app->get('news')
);
}
2.
YouMobe (11.04.2014 / 08:43)
$this->app->exists('text_prev') ? '' : $this->app->set('text_prev', "Вперед на ".$this->app->get("news")." публикаций<strong style=\"font-size: 20px;\"> →</strong></a>");
$this->app->exists('text_next') ? '' : $this->app->set('text_next', "<strong style=\"font-size: 20px;\">← </strong>Назад на ".$this->app->get("news")." публикаций</a>");
if(!$this->app->exists('admin_panel'))
{
$link['inc'] = "<a href='/category/".$category_id."/".($this->app->get('PARAMS.page')+1)."/'>".$this->app->get('text_next');
$link['dec'] = "<a href='/category/".$category_id."/".($this->app->get('PARAMS.page')-1)."/'>".$this->app->get('text_prev');
}
else
{
$link['inc'] = "<a href='".$this->app->get('admin_panel')."".($this->app->get('PARAMS.page')+1)."/'>".$this->app->get('text_next');
$link['dec'] = "<a href='".$this->app->get('admin_panel')."".($this->app->get('PARAMS.page')-1)."/'>".$this->app->get('text_prev');
}
$this->app->get('DB')->exec(
$query,
$query_params['inc']);
if($this->app->get('DB')->count() != NULL)
$this->app->set("next_page", $link['inc']);
$this->app->get('DB')->exec(
$query,
$query_params['dec']);
if($this->app->get('DB')->count() != NULL)
$this->app->set("prev_page", $link['dec']);
}
}
3.
____________________ (11.04.2014 / 09:16)
http://www.tigir.com/paging.htm
URL:
https://visavi.net/topics/40474