Adding Pagination
-----
| Author | Message | |
|---|---|---|
|
miranda1983 |
||
| Fri Aug 17, 2007 10:33 am Post subject: Adding Pagination | ||
|
I tried to build in a pagination in the Topic Extraction MOD
Code: if ($show == '' || $show == 'full')
{ $grab_topics = $db->sql_query = 'SELECT count(*) AS total FROM ' . phpbb_topics . ' WHERE forum_id = ' . 37 . ' ORDER BY topic_id DESC LIMIT ' . $start . ', ' . $board_config['topics_per_page']; } if ( !$result = $db->sql_query($sql) ) { message_die(GENERAL_ERROR, 'Error getting total', '', __LINE__, __FILE__, $sql); } if ( $total = $db->sql_fetchrow($result) ) { $total_pag_items = $total['total']; $page_url = "film.php?mode=$mode&order=$sort_order"; $pagination = generate_pagination($page_url, $total_pag_items, $board_config['topics_per_page'], $start); $pagination .= ' '; } $current_page = floor( $start / $board_config['topics_per_page'] ) + 1; $total_pages = ceil( $total_pag_items / $board_config['topics_per_page'] ); $template->assign_vars(array( 'PAGINATION' => $pagination, 'PAGE_NUMBER' => sprintf($lang['Page_of'], $current_page, $total_pages) )); but now I get this error: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in *******\mysql4.php on line 214 |
||
|
Thoul |
||
| Fri Aug 17, 2007 7:19 pm Post subject: Re: Adding Pagination | ||
|
This is not valid:
Code: $grab_topics = $db->sql_query = 'SELECT count(*) AS total
FROM ' . phpbb_topics . ' WHERE forum_id = ' . 37 . ' ORDER BY topic_id DESC LIMIT ' . $start . ', ' . $board_config['topics_per_page']; I think you might have accidentally overwritten some code there, as $db->sql_query = should never appear in your code when working with phpBB. If you try this, it should give better results: Code: $sql = 'SELECT count(*) AS total
FROM ' . phpbb_topics . ' WHERE forum_id = ' . 37 . ' ORDER BY topic_id DESC LIMIT ' . $start . ', ' . $board_config['topics_per_page']; |
||
|
miranda1983 |
||
| Sat Aug 18, 2007 2:56 am Post subject: | ||
|
Thank you for the reply.
I'm sorry, I didn't give the whole code This is de MOD: (whit de wrong code, but seperately from the pagination it works) Code: <?php
## Mod Title: Topic Extraction ## Version: 1.5.3 ############# ## Edit Below ############# // Where to take the topics from // Always a number $forum = '1'; // How many topics to show $limit = '2'; // How to show the topics // full or blank ('') $show = 'full'; // How to display the date and time if used // short or long $date_time = 'short'; // How top display the topic link if usede // topic or phpbb $topic_link_type = 'topic'; // Comments link - how to send them to comments // topic or reply $comment = 'topic'; // Path to your forums directory // Usually ./forum/ or ./phpBB/ or ./forums/ $phpbb_root_path = './forum/'; ############################################# ## No Editing unless you know what your doing ############################################# if ( !defined('IN_PHPBB') ) { define('IN_PHPBB', true); include($phpbb_root_path . 'extension.inc'); include($phpbb_root_path . 'common.'.$phpEx); include($phpbb_root_path . 'config.'.$phpEx); } if ($show == '' || $show == 'full') { // Select the topic information from the correct forum and set it to $grab_topics $grab_topics = $db->sql_query("SELECT * FROM `{$table_prefix}topics` WHERE `forum_id` = '{$forum}' AND `topic_moved_id` = '0' ORDER BY `topic_id` DESC LIMIT {$limit}"); } else if ($show == 'topic') { $grab_topics = $db->sql_query("SELECT * FROM `{$table_prefix}topics` WHERE `forum_id` = '{$forum}' AND `topic_id` = '{$_GET['t']}' ORDER BY `topic_id` DESC"); } // Grab the information using an array and set it to $echo_topic while ($echo_topic = $db->sql_fetchrow($grab_topics)) { // Select the post information from the correct forum and set it to $grab_posts $grab_posts = $db->sql_query("SELECT * FROM `{$table_prefix}posts` WHERE `forum_id` = '{$forum}' AND `topic_id` = '{$echo_topic['topic_id']}' LIMIT 1"); // Grab the information using an array and set it to $echo_post while ($echo_post = $db->sql_fetchrow($grab_posts)) { // Now get the post_text using the post_id were looking at and sort it info $grab_posts_text $grab_posts_text = $db->sql_query("SELECT * FROM `{$table_prefix}posts_text` WHERE `post_id` = '{$echo_post['post_id']}'"); // Grab the information using an array and set it to $echo_text while($echo_text = $db->sql_fetchrow($grab_posts_text)) { // Find the user the posted $find_user = $db->sql_query("SELECT * FROM `{$table_prefix}users` WHERE `user_id` = '{$echo_post['poster_id']}'"); // Sort this users info into array for the post while ($echo_user = $db->sql_fetchrow($find_user)) { // Get rid of all those annoying characters from bbcode $echo_text = preg_replace('/\:[0-9a-z\:]+\]/si', ']', $echo_text); // BBCode $echo_text = str_replace("[b]","<strong>",$echo_text); $echo_text = str_replace("[/b]","</strong>",$echo_text); $echo_text = str_replace("[i]","<em>",$echo_text); $echo_text = str_replace("[/i]","</em>",$echo_text); $echo_text = str_replace("[u]","<u>",$echo_text); $echo_text = str_replace("[/u]","</u>",$echo_text); $echo_text = preg_replace('/\[quote=(.*)\](.*)\[\/quote\]/Usi','<div style=\"padding: 7px\">$2</div>',$echo_text); $echo_text = str_replace("[quote]","<strong>Quote</strong><em>",$echo_text); $echo_text = str_replace("[/quote]","</em>",$echo_text); $echo_text = str_replace("[code]","<strong>Code</strong><em>",$echo_text); $echo_text = str_replace("[/code]","</em>",$echo_text); $echo_text = preg_replace('/\[list\](.*)\[\/list\]/si',"<div style=\"padding: 7px\">$1</div>",$echo_text); $echo_text = preg_replace('/\[list=(.*)\](.*)\[\/list\]/si',"<div style=\"padding: 7px\">$1</div>",$echo_text); $echo_text = str_replace("[img]","<img src=\"",$echo_text); $echo_text = str_replace("[/img]","\" alt=\"image\" />",$echo_text); $echo_text = preg_replace('/\[url\](.*)\[\/url\]/Usi','<a href="$1">$1</a>',$echo_text); $echo_text = preg_replace('/\[url=(.*)\](.*)\[\/url\]/Usi','<a href="$1">$2</a>',$echo_text); $echo_text = preg_replace('/\[color=(.*)\](.*)\[\/color\]/Usi','<span style="{color:$1}">$2</span>',$echo_text); $echo_text = preg_replace('/\[size=(.*)\](.*)\[\/size\]/Usi','<span style="{font-size:$1pt}">$2</span>',$echo_text); $echo_text = str_replace("\n", "\n<br />\n", $echo_text); // Way to display date and time // long if($date_time == "long") { $echo_topic['topic_time'] = strftime("%A %e %B %H:%M",$echo_topic['topic_time']); } // short if ($date_time == "short") { $echo_topic['topic_time'] = strftime("%a %e %b %H:%M",$echo_topic['topic_time']); } // Way to display comment link // Go right to the topic if ($comment == 'topic') { $comment_link = "{$phpbb_root_path}viewtopic.php?t={$echo_topic['topic_id']}"; } // Go right to the reply box if ($comment == 'reply') { $comment_link = "{$phpbb_root_path}posting.php?mode=reply&t={$echo_topic['topic_id']}"; } // Topic link types // This link goes to the topic display if ($topic_link_type == 'topic') { $topic_link = "?show1=topic&t={$echo_topic['topic_id']}"; } // This link goes to the actual phpbb topic if ($topic_link_type == 'phpbb') { $topic_link = "{$phpbb_root_path}viewtopic.php?t={$echo_topic['topic_id']}"; } ################################## ## Edit for look and feel of topic ################################## // Display just the title if ($show != 'full' && !isset($_GET['show1'])) { echo "<a href='{$topic_link}'>{$echo_text['post_subject']}</a><br />"; } // Display many topics - for news, shoutbox etc else if ($show == 'full') { echo " <strong>{$echo_text['post_subject']}</strong> by <strong>{$echo_user['username']}</strong> at <strong>{$echo_topic['topic_time']}</strong> <br /> <br /> {$echo_text['post_text']} <br /> <br /> <a href=\"{$comment_link}\">Comments {$echo_topic['topic_replies']}</a> <hr size=\"1\"> "; } // Display the topic for when used with the one above, click link and go here if ($_GET['show1'] == 'topic') { echo " <strong>{$echo_text['post_subject']}</strong> by <strong>{$echo_user['username']}</strong> at <strong>{$echo_topic['topic_time']}</strong> <br /> <br /> {$echo_text['post_text']} <br /> <br /> <a href=\"{$comment_link}\">Comments {$echo_topic['topic_replies']}</a> <hr size=\"1\"> "; } } } } } ?> I want a pagination to it but don't know how to rewrite $db->sql_query from the MOD. |
||
|
Thoul |
||
| Sat Aug 18, 2007 4:18 pm Post subject: Re: Adding Pagination | ||
|
Have a look at this tutorial; it may help you out: Adding Pagination to a phpBB Page
I also recommend changing this line in the mod: Code: $grab_topics = $db->sql_query("SELECT * FROM `{$table_prefix}topics` WHERE `forum_id` = '{$forum}' AND `topic_id` = '{$_GET['t']}' ORDER BY `topic_id` DESC"); To this: Code: $grab_topics = $db->sql_query("SELECT * FROM `{$table_prefix}topics` WHERE `forum_id` = '{$forum}' AND `topic_id` = '" . intval($_GET['t']) . "' ORDER BY `topic_id` DESC"); There is a big security hole in that mod that will be fixed by this change. |
||
|
miranda1983 |
||
| Sun Aug 19, 2007 10:57 am Post subject: | ||
|
Thank you, Thoul
I know that tutorial, I tried to use that pagination script with Topic Extraction MOD, see my first post. The pagination works great en also does the MOD but I just can't get it together. |
||
Page 1 of 1