Announcement

Collapse
No announcement yet.

Pages (11): [1] 2 3 » ... Last »

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Pages (11): [1] 2 3 » ... Last »

    i wouldl like to do something like this:

    Pages (11): [1] 2 3 » ... Last »

    any idea how i should start??

  • #2
    Take a look here:

    http://www.phpbuilder.com/columns/rod20000221.php3
    Five Star Review Script - Add reviews to your website!
    Mixed Martial Arts - Houston MMA Training
    Women's Self-Defense - Courses and DVDs available

    Comment


    • #4
      Please can someone tell me how to do this when the values are stored in a text file?
      The guestbook I am using has previous and next links at the bottom of the page. Is there any way I can change the code to display Pages (11): [1] 2 3 » ... Last » instead.
      The code which generates the previous and next page links is:

      Code:
       // display entries
        function _displayEntry($start_entry, $MAX_PER_PAGE) {
          $end = FALSE;
          $guestbook_array = file($this->guestbook_dat);
          for ($i = sizeof($guestbook_array) - $start_entry, $j = $MAX_PER_PAGE; $i >= 0 && $j > 0; $i--, $j--) {
            $guestbook_line = explode("|", $guestbook_array[$i]);
      
            # empty strings must be substituted by " " to display the HTML correctly
            for ($k = 0; $k < sizeof($guestbook_line); $k++) {
              if (!strcmp($guestbook_line[$k], ""))
                $guestbook_line[$k] = " ";
            }
      
            $this->name = $guestbook_line[0];
            $this->email = $guestbook_line[1];
            $this->icq = $guestbook_line[2];
            $this->homepage = $guestbook_line[3];
            $this->ip = $guestbook_line[4];
            $this->entry = $guestbook_line[5];
            $this->timestamp = $guestbook_line[6];
      
            # check, if there are any older entries in the datafile
            if ($i < 1)
              $end = TRUE;
      
            include($this->entry_html_code);
                 
          }        
          return $end;
        }
        
      
      
        // display links to browse the entries
        function _displayLinks($start_entry, $end) {
      
          # this will add a link to newer entries, if there are some
          if (($back = $start_entry - 10) > 0) {
            $link = "<a href=\"$this->pageName?start_entry=$back\">«Previous Page</a> <b>l</b> ";
          }
      
          # this will add a link to older entries, if there are some
          if (!$end) {
            $start_entry += 10;
            $link .= "<a href=\"$this->pageName?start_entry=$start_entry\">Next Page»</a>";
          }
      
          return $link;
        }
      Thank you

      Comment


      • #5
        First of all you need to get the number of entries to the line creation function. I supposes that both the functuions are called from the same routine.

        The best way would probably be to change the input from start_entry to page.

        I hope you know how to do that.

        Then change the _displayEntry function to be
        PHP Code:
        function _displayEntry($page$MAX_PER_PAGE) {
            
        $guestbook_array file($this->guestbook_dat);
            
        $pages=ceil(sizeof($guestbook_array)/$MAX_PER_PAGE);

            for (
        $i sizeof($guestbook_array) - ($page-1)*$MAX_PER_PAGE-1$j $MAX_PER_PAGE$i >= && $j 0$i--, $j--) {
              
        $guestbook_line explode("|"$guestbook_array[$i]);

              
        # empty strings must be substituted by " " to display the HTML correctly
              
        for ($k 0$k sizeof($guestbook_line); $k++) {
                if (!
        strcmp($guestbook_line[$k], ""))
                  
        $guestbook_line[$k] = " ";
              }

              
        $this->name $guestbook_line[0];
              
        $this->email $guestbook_line[1];
              
        $this->icq $guestbook_line[2];
              
        $this->homepage $guestbook_line[3];
              
        $this->ip $guestbook_line[4];
              
        $this->entry $guestbook_line[5];
              
        $this->timestamp $guestbook_line[6];

              include(
        $this->entry_html_code);
                   
            }        
            return 
        $pages;
          } 
        If I've done everything correctly the function will now take a page and output that page. It will then return the number of pagest in the book.


        Now you change the other function to be called with $page, $pages
        PHP Code:
        // display links to browse the entries
          
        function _displayLinks($page$pages) {
            
        $pages_shown=3;
            
        $link "Pages (".$pages."): ";

            
        $minpage=$page-$pages_shown;
            if (
        $minpage<1) {
               
        $minpage=1;
            }
            
        $maxpage=$page+$pages_shown;
            if (
        $maxpage>$pages) {
               
        $maxpage=$pages;
            }


            if (
        $minpage!=1) {
            
        $link.= "<a href=\"$this->pageName?page=1\">«First</a> ... ";
            }
            if (
        $page>1) {
                
        $linkpage=$page-1;
                
        $link.= "<a href=\"$this->pageName?page=$linkpage\">«</a> ";
            }

            for(
        $linkpage=$minpage;$linkpage<$maxpage;$linkpage++) {
                if (
        $linkpage==$page) {
                   
        $link.="[$linkpage] ";
                } else {
                   
        $link.= "<a href=\"$this->pageName?page=$linkpage\">$linkpage</a> ";

                }
            }
            if (
        $page<$pages) {
                
        $linkpage=$page+1;
                
        $link.= "<a href=\"$this->pageName?page=$linkpage\">»</a> ";
            }
            if (
        $maxpage!=$pages) {
            
        $link.= "<a href=\"$this->pageName?page=$pages\">Last»</a> ... ";
            }

            return 
        $link;
          } 

        I hope this will work for you.

        Comment


        • #6
          Thanks, I will try this

          Comment

          widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
          Working...
          X