db paging in plugin
db paging in plugin
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
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
-
- Core Developer
- Posts: 30022
- Joined: Tue Sep 16, 2003 9:45 pm
- Location: Cologne, Germany
- Contact:
Re: db paging in plugin
Sorry, I don't understand what you mean, please describe it exactly.
Regards,
Garvin
Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
-
- Core Developer
- Posts: 30022
- Joined: Tue Sep 16, 2003 9:45 pm
- Location: Cologne, Germany
- Contact:
Ah, okay.
Well, pagination is really simple:
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
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>';
}
Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
In case someone wants to use this...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;
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
-
- Core Developer
- Posts: 30022
- Joined: Tue Sep 16, 2003 9:45 pm
- Location: Cologne, Germany
- Contact:
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>';
}
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
There is a more efficient way...
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.
http://dev.mysql.com/doc/mysql/en/infor ... tions.html
Just FYI, but I thought it was quite a cool feature.
-
- Core Developer
- Posts: 30022
- Joined: Tue Sep 16, 2003 9:45 pm
- Location: Cologne, Germany
- Contact:
Re: There is a more efficient way...
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
Thanks for the pointer, though!
Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
-
- Regular
- Posts: 1331
- Joined: Sun Dec 04, 2005 5:43 pm
- Location: Andalucia, Spain
- Contact:
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
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
-
- Core Developer
- Posts: 30022
- Joined: Tue Sep 16, 2003 9:45 pm
- Location: Cologne, Germany
- Contact:
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
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
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
-
- Regular
- Posts: 1331
- Joined: Sun Dec 04, 2005 5:43 pm
- Location: Andalucia, Spain
- Contact: