Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5950895
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:27:33+00:00 2026-05-22T17:27:33+00:00

Here are some pagination function code. how to transfer sprintf to print_r or echo

  • 0

Here are some pagination function code. how to transfer sprintf to print_r or echo? For I want add class into a href and add more onclick thing. Thanks.

public function display() {
        extract($this->_arrTemplateData);

        if($total_pages <= $visible_pages) {
            $page_start = 1;
            $page_end = $total_pages;
        } else if($page <= ceil($visible_pages/2)) {
            $page_start = 1;
            $page_end = $visible_pages;
        } else if($page > ($total_pages - ceil($visible_pages/2))) {
            $page_start = $total_pages - (ceil(($visible_pages/2)*2)-1);
            $page_end = $total_pages;
        } else {
            $page_start = $page-(floor($visible_pages/2));
            $page_end = $page+(floor($visible_pages/2));
        }
        $return = sprintf(
               '<div class="summary"><p class="pages">%u %s</p><p class="total">%u %s</p></div>'
            ,$total_pages
            ,$total_pages == 1?'Page':'Pages'
            ,$found_rows
            ,$found_rows == 1?$label:$label
        );
        $return.= sprintf('<ul class="pagination">');
        $return.= sprintf(
            '<li class="first">%s%s%s</li>'
            ,$page == 1?'':sprintf('<a href="%s">',str_replace($page_flag,1,$base_path))
            ,'First'
            ,$page == 1?'':'</a>'
        );    
        $return.= sprintf(
            '<li class="previous">%s%s%s</li>'
                ,$page == 1?'':sprintf('<a href="%s">',str_replace($page_flag,($page-1),$base_path))
            ,'Previous'
            ,$page == 1?'':'</a>'
        );
        foreach(range($page_start,$page_end,1) as $i) {
            $return.= sprintf(
                '<li%s>%s%s%s</li>'
                ,$page == $i?' class="current"':''
                ,$page == $i?'':sprintf('<a href="%s">',str_replace($page_flag,$i,$base_path))
                ,$i
                ,$page == $i?'':'</a>'
            );
        }
        $return.= sprintf(
            '<li class="next">%s%s%s</li>'
            ,$page == $total_pages?'':sprintf('<a href="%s">',str_replace($page_flag,($page+1),$base_path))
            ,'Next'
            ,$page == $total_pages?'':'</a>'
        );
        $return.= sprintf(
            '<li class="last">%s%s%s</li>'
            ,$page == $total_pages?'':sprintf('<a href="%s">',str_replace($page_flag,$total_pages,$base_path))
            ,'Last'
            ,$page == $total_pages?'':'</a>'
        );
        $return.= sprintf('</ul>');
        return $return;
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T17:27:34+00:00Added an answer on May 22, 2026 at 5:27 pm

    By calling the function from the class and printing its content

    $obj = new ClassName(); // your class name
    
    echo $obj->display();
    
    print_r($obj->display());
    

    is that what you are trying to accomplish?

    also in smaller note:

    Some times there is no point in using sprintf() like $return.= sprintf('</ul>');
    simply assign it to the variable like so:

    $return.= '</ul>';
    

    UPDATE:

    To answer your comment, you can simply type the same variable twice or n times:

    $return = sprintf('<a href="%s" onclick=\"javascript:func("%s")\" class="link">'
              $url,$url);
    

    or for this particular caase u can use a javascript fix:

    $return = sprintf('<a href="%s" onclick=\"func(this.href)\" class="link">',$url);
    

    UPDATE2:

    Your code is not easy to debug, here is how i suggest you rewrite it, and it will make much more sense when you want to debug.

    $new_path = $page == $total_pages? '': str_replace($page_flag,$total_pages,$base_path));
    $end = $page == $total_pages?'':'</a>';
    $return.= sprintf('<li class="last">%s%s%s</li>',$new_path,'Last',$end);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to apply pagination for some class of my application, in which i
Here is some code I could not get to format properly in markdown, this
Here's some Ruby code: puts %x{ pstree #{$$} } # never forks puts %x{
Here's some code I saw once. Can you see what's wrong with it? [updated]
here is some sample javascript: SomeObjectType = function() { } SomeObjectType.prototype = { field1:
Here is some simple code: DIR* pd = opendir(xxxx); struct dirent *cur; while (cur
Here's some code (full program follows later in the question): template <typename T> T
i want to use doctrine with zend_paginator here some example query : $allArticleObj =
I made some alterations to my code, and now it won't function properly. My
Here is some simple Perl to count the number of times a value occurs

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.