Page 1 of 1

db paging in plugin

Posted: Wed Apr 27, 2005 1:20 pm
by Timbalu
Hi Gravin

How can I use serendipities (entry)paging functions inside a new plugin?
Is there an example?
I do not mean the entry table date, its a new plugin table.
I tried to include a paginator class I always used, but this gets messed up with s9y classes.

Thanks in advance
Ian

Re: db paging in plugin

Posted: Wed Apr 27, 2005 2:48 pm
by garvinhicking
Sorry, I don't understand what you mean, please describe it exactly. :)

Regards,
Garvin

Posted: Wed Apr 27, 2005 3:18 pm
by Timbalu
well.... I´ll try ;)
I need a n Entries/next/previous paging function for some db data.
I tried to have a look at entrypaging plugin, bur I could not find the right
Idea how to use this sort of stuff for a new plugin I want to use.

Posted: Wed Apr 27, 2005 3:51 pm
by garvinhicking
Ah, okay.

Well, pagination is really simple:

Code: Select all

$min_page = 0;
$results_per_page = 15;
$current_page = $serendipity['GET']['page'];
if (empty($current_page)) {
  $current_page = $min_page;
}

$result = serendipity_db_query("SELECT * FROM yourstuff " . serendipity_db_limit_sql(serendipity_db_limit($current_page * $results_per_page, $results_per_page)));

$max_page = count($result) / $results_per_page;

echo "You are on Page " . ($current_page+1) . " of " . ($max_page+1) . " pages. Go to page:<br />";
for ($i = $min_page; $i <= $max_page; $i++) {
  echo '<a href="index.php?serendipity[subpage]=stuff&serendipity[page]=' . $i . '">' . $i . '</a>';
}
It's even so simple that creating functions for this is pretty much overhead and unneeded in most plugin cases that have to freeform their output nevertheless. :)

Regards,
Garvin

Posted: Wed Apr 27, 2005 4:30 pm
by Timbalu
Ahhhh, simple and effective!
Merci bien!
Ian

Posted: Wed Apr 27, 2005 10:17 pm
by Timbalu
garvinhicking wrote:

Code: Select all

$result = serendipity_db_query("SELECT * FROM yourstuff " . serendipity_db_limit_sql(serendipity_db_limit($current_page * $results_per_page, $results_per_page)));

$max_page = count($result) / $results_per_page;
In case someone wants to use this...
count($result) will not give you the full sum of items of your table, because the db_limit_sql function will not allow it.
You need a resultset without those limit functions.

Ian

Posted: Thu Apr 28, 2005 2:08 pm
by garvinhicking
Ah, that's true, thanks for noticing. I adapted the code:

Code: Select all

$min_page = 0;
$results_per_page = 15;
$current_page = $serendipity['GET']['page'];
if (empty($current_page)) {
  $current_page = $min_page;
}

$fullresult = serendipity_db_query("SELECT count(*) AS counter FROM yourstuff", true);

$result = serendipity_db_query("SELECT * FROM yourstuff " . serendipity_db_limit_sql(serendipity_db_limit($current_page * $results_per_page, $results_per_page)));

$max_page = $fullresult['counter'] / $results_per_page;

echo "You are on Page " . ($current_page+1) . " of " . ($max_page+1) . " pages. Go to page:<br />";
for ($i = $min_page; $i <= $max_page; $i++) {
  echo '<a href="index.php?serendipity[subpage]=stuff&serendipity[page]=' . $i . '">' . $i . '</a>';
} 

There is a more efficient way...

Posted: Thu Apr 28, 2005 9:15 pm
by Synchro
Check out the MySQL FOUND_ROWS() function:

http://dev.mysql.com/doc/mysql/en/infor ... tions.html

Just FYI, but I thought it was quite a cool feature.

Re: There is a more efficient way...

Posted: Fri Apr 29, 2005 2:07 pm
by garvinhicking
Sadly this is MySQL only and would not work on our PostgreSQL or SQLite backends, thus I don't encourage it's usage.

Thanks for the pointer, though! :)

Regards,
Garvin

Posted: Sat Feb 04, 2006 6:04 am
by carl_galloway
Hi all,

I'm trying to work out whether I can use smarty to add entry paging to a hard-coded location on the detail page of a theme. I don't want to use the entrypaging plugin because it outputs additional divs, I simply want to use smarty much like I do for the next prev links in overview mode.

So basically I want to;

if overview page, then next prev is next prev overview page
elseif detail page, then next prev is next detail page

if this is possible, then we wouldn't need the entry paging plugin at all, we would just need to call the appropriate variable either $footer_next_page, or $detailfooter_next_page. And the same for the previous pages.

Could this be done, and apologies for posting here, I just thought since this thread is already open I might add to it.

Carl

Posted: Sat Feb 04, 2006 2:15 pm
by garvinhicking
Hi Carl!

I've patched up this: http://nopaste.php-q.net/189279

It inserts these smarty variables if you set the plugin config placement to smarty:

{$pagination_(next|prev|random)_(title|link)}

Regards,
Garvin

Posted: Sat Feb 04, 2006 6:36 pm
by carl_galloway
I'll go and try that and let you know how it works, thanks.

Carl