Paginating script help …

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
perik
Forum Newbie
Posts: 6
Joined: Tue May 10, 2005 5:18 am

Paginating script help …

Post by perik »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi!

Im using the community e107 and want to hack one of their scripts. The script lists the content in alphabetic order. 

I would like to have max 10 results per page and then paginating with next and previous buttons. 

Something like this:

< prev 1 2 3 … 9 10 11 next >

How do I make this?

Theres a shortcode in the e107 that is called NEXTPREV

Heres an codeexample for this that Ive gotten from this page:
http://wiki.e107.org/?title=Shortcodes: ... d:NEXTPREV


Shortcodes:Frontend:NEXTPREV
From e107 Wiki
This code is used to generate the next/previous buttons often found on pages that contain long listings from the database. The following example, will display 30 rows from the database on each page.

Code: Select all

$from = ($_GET['frm']) ? $_GET['frm'] : 0;
  $view = 30;

  $total = $sql -> db_Select("download", "*", "download_author='$usernm'");
  $sql -> db_Select("download", "*", "download_author='$usernm' LIMIT $from,$view");
  while($row = $sql-> db_Fetch()){
     $text .= "text-here".$row['fieldname'];
   }

 $parms = $total_items.",".$view.",".$from.",".e_SELF.'?frm=[FROM]';
 $text .= $tp->parseTemplate("{NEXTPREV={$parms}}");

echo $text;
Ive tried to insert this into my page but it need to be modified but I cant figure out how. Or have you got any other code I can use.

Heres the the code from the e107 file which lists the content in alphabetic order:

Code: Select all

<?php
/*
|   This script lists content pages by alphabetical order with buttons for letters
|   Tested for v0.7.7 and it is originally adapted from v0.617:
+---------------------------------------------------------------+
*/
require_once("../../class2.php");
require_once(HEADERF);
require_once(e_HANDLER."form_handler.php");
require_once(e_HANDLER."userclass_class.php");
$lan_file = $plugindir.'languages/'.e_LANGUAGE.'/lan_toc.php';
include_once(file_exists($lan_file) ? $lan_file : $plugindir.'languages/English/lan_toc.php');

// ##### Display scrolling list of existing content pages ------------------------------------

$text = "";
// -------- SHOW FIRST LETTERS FIRSTNAMES ------------------------------------
$sql = new db;
$distinctfirstletter = $sql -> db_Select("pcontent", "DISTINCT(LEFT(content_heading,1)) as letter", "LEFT(content_parent,1)!='0' ORDER BY content_heading ASC ");
if ($distinctfirstletter != 1){
$text .= "<form method='post' action='".e_SELF."'>
                <table class='fborder' style='width:100%'>
                <tr><td colspan='2' class='forumheader'>".CONTENT_TOC_LAN_3."</td></tr>
                <tr><td colspan='2' class='forumheader3'>";
                while($row = $sql-> db_Fetch()){
                extract($row);
                        $text .= "<input class='button' style='width:20' type='submit' name='letter' value='".strtoupper($letter)."' />";
                }
                $text .= "
                <input class='button' style='width:20' type='submit' name='letter' value='".CONTENT_TOC_LAN_6."' />
                </td></tr>
                </table></form> ";
        }

        // ---------------------------------------------------------------------------

        // -------- CHECK FOR FIRST LETTER SUBMISSION --------------------------------
        $sql = new db;
        $letter=$_POST['letter'];
        if ($_POST['letter'] != "" && $_POST['letter'] != CONTENT_TOC_LAN_6 ) {
                $letter = $_POST['letter'];
                $query = "LEFT(content_parent,1)!='0' AND content_heading LIKE '".$letter."%' ORDER BY content_heading ASC";
        } else {
                        $query = "LEFT(content_parent,1)!='0' ORDER BY content_heading ASC";
                }
        // ---------------------------------------------------------------------------

        $sql2 = new db;
        $text .= "<div style='border : solid 1px #000; padding : 4px; width : auto; height : 600px; overflow : auto; '>";
        if($article_total = $sql -> db_Select("pcontent", "*", $query)){
                if($article_total < 50 || $letter || $cat){
                        $text .= "<table class='fborder' style='width:100%'>
                        <tr>
                        <td style='width:5%' class='forumheader2'>&nbsp;</td>
                        <td style='width:95%' class='forumheader2'>".CONTENT_TOC_LAN_2."</td>

                        </tr>";
                        while($row = $sql -> db_Fetch()){
                                extract($row);
                            if(check_class($content_class)){
                                unset($cs);
                                $delete_heading = str_replace("'", "\'", $content_heading);
                                if($sql2 -> db_Select("pcontent", "content_heading", "content_id=$content_parent")){
                                        $row = $sql2 -> db_Fetch(); $cs = $row[0];
                                }
                                $text .= "<tr>
                                <td style='width:5%; text-align:center' class='forumheader3'><img src='".e_PLUGIN."content/images/content_32.png' alt='' style='border:0' /></td>
                                <td style='width:75%' class='forumheader3'><a href='".e_PLUGIN."content/content.php?content.$content_id'>$content_heading</a> </td>
                                </td>
                                </tr>";
                             }
                        }
                        $text .= "</table>";
                } else {
                        $text .= "<br /><div style='text-align:center'>".CONTENT_TOC_LAN_4."</div>";
                }
        } else {
                $text .= "<div style='text-align:center'>".CONTENT_TOC_LAN_1."</div>";
        }
        $text .= "</div>";

        $caption = "".CONTENT_TOC_LAN_5."\n<a href='".e_PLUGIN."content/content.php?'>".CONTENT_TOC_LAN_7."</a>";
        $ns -> tablerender($caption, $text);

// ##### End ---------------------------------------------------------------------------------------------------------------------------------------------------------------------

require_once(FOOTERF);

?>
Ive replaced this line

Code: Select all

if($article_total = $sql -> db_Select("pcontent", "*", $query)){
into:

Code: Select all

$view = 10;			
if($article_total = $sql -> db_Select("pcontent", "*", "$query LIMIT $view")){
to limit the displayed content to 10 only.

Any idea how I can insert paginating???

Thanks a lot

Perik


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Post Reply