Codice PHP:
$start = isset($_GET['start']) ? intval($_GET['start']) : 0;
$start = ($start < 0) ? 0 : $start;
$max_number_challenge_listing = 5;
$page_number = (isset($_GET['page_number']) ? intval($_GET['page_number']) : (isset($_POST['page_number']) ? intval($_POST['page_number']) : false));
$page_number = ($page_number < 1) ? false : $page_number;
$start = (!$page_number) ? $start : (($page_number * $max_number_challenge_listing) - $max_number_challenge_listing);
$sql = 'SELECT *, (SELECT COUNT(id) FROM '. CHALLENGE_TABLE.') AS total_challenge
FROM ' . CHALLENGE_TABLE . '
LIMIT ' . $start . ', ' . $max_number_challenge_listing;
if (!($result = $db->sql_query($sql)))
{
message_die(GENERAL_ERROR, 'Could not read id challenge.', '', __LINE__, __FILE__, $sql);
}
$challenge_page_title = 'Lista Sfide';
$row = $db->sql_fetchrow($result);
$total_challenge = $row['total_challenge'];
$pagination = generate_pagination(U_CHALLENGE . '?a=a', $total_challenge, $max_number_challenge_listing, $start);
$template->assign_vars(array(
'PAGINATION' => $pagination,
'PAGE_NUMBER' => sprintf($lang['Page_of'], (floor($start / intval($max_number_challenge_listing)) + 1), ceil($total_challenge / intval($max_number_challenge_listing))),
'TOTAL_CHALLENGE' => $total_challenge,
));
}
La funzione generate_pagination() è questa:
Codice PHP:
function generate_pagination($base_url, $num_items, $per_page, $start_item, $add_prevnext_text = true, $start = 'start')
{
global $lang;
$total_pages = ceil($num_items / $per_page);
if ($total_pages == 1)
{
return ' ';
}
$on_page = floor($start_item / $per_page) + 1;
$page_string = '';
if ($total_pages > 10)
{
$init_page_max = ($total_pages > 3) ? 3 : $total_pages;
for($i = 1; $i < $init_page_max + 1; $i++)
{
$page_string .= ($i == $on_page) ? '<b>' . $i . '</b>' : '<a href="' . append_sid($base_url . '&' . $start . '=' . (($i - 1) * $per_page)) . '">' . $i . '</a>';
if ($i < $init_page_max)
{
$page_string .= ', ';
}
}
if ($total_pages > 3)
{
if (($on_page > 1) && ($on_page < $total_pages))
{
$page_string .= ($on_page > 5) ? ' ... ' : ', ';
$init_page_min = ($on_page > 4) ? $on_page : 5;
$init_page_max = ($on_page < $total_pages - 4) ? $on_page : $total_pages - 4;
for($i = $init_page_min - 1; $i < $init_page_max + 2; $i++)
{
$page_string .= ($i == $on_page) ? '<b>' . $i . '</b>' : '<a href="' . append_sid($base_url . '&' . $start . '=' . (($i - 1) * $per_page)) . '">' . $i . '</a>';
if ($i < $init_page_max + 1)
{
$page_string .= ', ';
}
}
$page_string .= ($on_page < $total_pages - 4) ? ' ... ' : ', ';
}
else
{
$page_string .= ' ... ';
}
for($i = $total_pages - 2; $i < $total_pages + 1; $i++)
{
$page_string .= ($i == $on_page) ? '<b>' . $i . '</b>' : '<a href="' . append_sid($base_url . '&' . $start . '=' . (($i - 1) * $per_page)) . '">' . $i . '</a>';
if($i < $total_pages)
{
$page_string .= ', ';
}
}
}
}
else
{
for($i = 1; $i < $total_pages + 1; $i++)
{
$page_string .= ($i == $on_page) ? '<b>' . $i . '</b>' : '<a href="' . append_sid($base_url . '&' . $start . '=' . (($i - 1) * $per_page)) . '">' . $i . '</a>';
if ($i < $total_pages)
{
$page_string .= ', ';
}
}
}
if ($add_prevnext_text)
{
if ($on_page > 1)
{
$page_string = ' <a href="' . append_sid($base_url . '&' . $start . '=' . (($on_page - 2) * $per_page)) . '">' . $lang['Previous'] . '</a> ' . $page_string;
}
if ($on_page < $total_pages)
{
$page_string .= ' <a href="' . append_sid($base_url . '&' . $start . '=' . ($on_page * $per_page)) . '">' . $lang['Next'] . '</a>';
}
}
$page_string = ($page_string != '') ? $lang['Goto_page'] . ' ' . $page_string : ' ';
return $page_string;
}
Solo che mi stampa tutto, tranne il primo e l'ultimo record.
Codice:
CREATE TABLE IF NOT EXISTS `ip_challenge` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`id_challenger` int(11) NOT NULL,
`id_challenging` int(11) NOT NULL,
`state` int(2) NOT NULL,
`date_launch` int(11) NOT NULL,
`days_accept` int(11) NOT NULL,
`days_send_image` int(11) NOT NULL,
`days_vote` int(11) NOT NULL,
`type_challenge` varchar(20) NOT NULL,
`vote_challenger` int(11) NOT NULL,
`vote_challenging` int(11) NOT NULL,
`notes` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=7 ;
INSERT INTO `ip_challenge` (`id`, `id_challenger`, `id_challenging`, `state`, `date_launch`, `days_accept`, `days_send_image`, `days_vote`, `type_challenge`, `vote_challenger`, `vote_challenging`, `notes`) VALUES
(1, 2, 3, 0, 1237080372, 5, 5, 5, 'signature', 2, 56, 'Nota'),
(2, 2, 3, 1, 1232633097, 3, 2, 5, 'icon', 3, 6, ''),
(3, 3, 2, 2, 1232633097, 4, 3, 9, 'free', 0, 0, ''),
(4, 2, 3, 3, 1232633097, 3, 4, 5, 'remake', 0, 0, 'Note quarta sfida \\m/ <a href="#">Testo</a>'),
(5, 3, 2, 4, 1232633097, 3, 4, 5, 'colorize', 4, 6, ''),
(6, 3, 2, 5, 1232633097, 3, 3, 3, 'icon', 2, 2, '');
Mi potete dire dove sta l'errore?? Mi sto sbattendo ma non riesco a cavarne piede