Pagination

Discussion forum for MOD Writers regarding MOD Development.
Locked
User avatar
hah
Registered User
Posts: 85
Joined: Sat Feb 13, 2010 11:49 am
Location: Pernik, Bulgaria
Name: Alex Georgiev
Contact:

Pagination

Post by hah »

Can someone help me with pagination for this code:

Code: Select all

$sql = 'SELECT * FROM phpbb_yroci WHERE approved = 1 ORDER BY id DESC';
    $result = $db->sql_query($sql);

    while ($row = $db->sql_fetchrow($result))
    {
$avtor = $row['avtor'];
    $template->assign_block_vars('loop', array(

       'YROK_IME'         => $row['ime'],
       'YROK_DATA'         => $row['yrok_data'],
       'YROK_AVTOR'         => $row['avtor'],
       'YROK_ID'         => $row['id'],
       'APPROVED'         => $row['approved'],
       'YROK_AVTOR_PROFILE'         => append_sid("{$phpbbb_root_path}memberlist.$phpEx", "mode=viewprofile&un=$avtor"),
    ));
    }
I saw other topics, but I don't understand some codes and..

User avatar
daroPL
Translator
Posts: 515
Joined: Tue Mar 27, 2007 11:58 am
Location: Poznan, Poland
Name: Darek
Contact:

Re: Pagination

Post by daroPL »


User avatar
hah
Registered User
Posts: 85
Joined: Sat Feb 13, 2010 11:49 am
Location: Pernik, Bulgaria
Name: Alex Georgiev
Contact:

Re: Pagination

Post by hah »

I told you really really clearly that I don't understand the code.
If I knew how it works that way I won't post here.
Please I need some example..
PS even the code in the examples is wrong..
[phpBB Debug] PHP Notice: in file /etccode.php on line 21: implode() [function.implode]: Invalid arguments passed

There is null $params..

User avatar
daroPL
Translator
Posts: 515
Joined: Tue Mar 27, 2007 11:58 am
Location: Poznan, Poland
Name: Darek
Contact:

Re: Pagination

Post by daroPL »

As you saw that's only an example. What specifically don't you understand in that code?

User avatar
John P
Registered User
Posts: 1237
Joined: Mon Jan 21, 2008 3:55 pm
Location: Netherlands
Name: John
Contact:

Re: Pagination

Post by John P »

Calculate how many rows you have

$sql = 'SELECT COUNT(id) as num_posts FROM phpbb_yroci WHERE approved = 1 ORDER BY id DESC';
$result = $db->sql_query($sql);
$total_posts = (int) $db->sql_fetchfield('num_posts');

Knowing that look at the start
if ($start < 0 || $start >= $total_posts)
{
$start = ($start < 0) ? 0 : floor(($total_posts - 1) / $config['posts_per_page']) * $config['posts_per_page'];
}

The run your query using
$result = $db->sql_query_limit($sql, $config['posts_per_page'], $start);
Image
Webhosting, Custom MODs, Technical management, MOD installation and Webdesign

User avatar
hah
Registered User
Posts: 85
Joined: Sat Feb 13, 2010 11:49 am
Location: Pernik, Bulgaria
Name: Alex Georgiev
Contact:

Re: Pagination

Post by hah »

Ok I get everything, but I have a problem.
The 1, 2 • Page 1 from 2 is shown and they are clickable and the pagination with start=5,10,1,2,3 it works, I change the topics per page value and if its 1 I get 1,2,3,4,5,6 if its 5 topics per page I get 1,2, so it seems to be correct, but on whatever page I am it shows all the articles, not only the one that are on the page, where am I it shows everything.

Here is it the code:

Code: Select all

$start	= request_var('start', 0);

$sql = 'SELECT COUNT(id) AS total_yroci
			FROM phpbb_yroci';
		$result = $db->sql_query($sql);
		$total_yroci = (int) $db->sql_fetchfield('total_yroci');
		$db->sql_freeresult($result);
		$pagination_url = append_sid("{$phpbb_root_path}yrok_list_backup.$phpEx");
     
     $template->assign_vars(array(
			'PAGINATION'	=> generate_pagination($pagination_url, $total_yroci, $config['topics_per_page'], $start),
			'PAGE_NUMBER'	=> on_page($total_yroci, $config['topics_per_page'], $start),
		));
I'm pretty sure that its from the

Code: Select all

$result = $db->sql_query_limit($sql, $config['posts_per_page'], $start);
, but I can't find where it should be..

Edit: Fixed it. Thanks for the responses. :)

Locked

Return to “[3.0.x] MOD Writers Discussion”