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

  • SEARCH
  • Home
  • 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 5962921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:10:26+00:00 2026-05-22T19:10:26+00:00

there i have created a program with a tab button and page number. all

  • 0

there i have created a program with a tab button and page number. all functions are almost working properly until i noticed one tiny problem. as we all know, tabs always highlights the current tab you are in. let us say if your tabs are A-Z letters and a # that means home or mainpage, and your # is the current page, and the main pages consist of the list of employees registered in your database. since i have page number (Next and Previous), i have limited the amount or number of employee names/information by 5 stating that only 5 records should appear on the screen.

note: my code is working, but 1 problem slipped. everytime i clicked on the next button to see the other list of employees,the # tab is not highlighted wherein its suppose to still be highlighted since you are in the same page. Does anyone knows what cause this and how to fix it? im sorry if it is not that clear since it is so hard to explain.

example:(IMAGINE THIS AS THE WINDOW) let us say the limit is = 2

**#** A B C D E F G H I J K L M N O P Q R S T U V W X Y Z  //this is the tabs button, notice the # is highlighted
employee_id : employee_name : employee_age
     1          chel                26
     2         brandon              35
**PREV**                                 **NEXT**     //this is the page number

when i try to click next to view the next employee in the main page, the page looks like this:

# A B C D E F G H I J K L M N O P Q R S T U V W X Y Z //notice the # is NOT highlighted after you click next
employee_id : employee_name : employee_age
     3          charlie            28
     4           sasha             24
**PREV**                                 **NEXT**

i hope i cleared up my problem in this simple illustration. i hope someone could help me. thanks

//this is my tabs codes
<?php
                function toc_menu($current){
                    $return ='<ol id="toc">
                    '."\n";
                    $return .= ($current=='') ? '<li class="current"><a href="index.php?namelist=%"><span>#</span></a></li>'."\n" : '<li><a href="index.php"><span>#</span></a></li>'."\n";
                    foreach(range('a','z') as $link){
                    $return .= ($current==$link) ? '<li class="current"><a href="index.php?namelist='.$link.'"><span>'.strtoupper($link).'</span></a></li>'."\n" : '<li><a href="index.php?namelist='.$link.'"><span>'.strtoupper($link).'</span></a></li>'."\n";
                    }
                    $return .="</ol>\n";
                    return $return;
                }
            if(isset($_GET['namelist']))
            {
            $current=$_GET['namelist'];
            }
            else
            {$current='';
            }

            //echo where you want the menu
            if(isset($_GET['namelist'])) {
                echo toc_menu(strtolower($_GET['namelist']));
                $tocmenu = toc_menu(strtolower($_GET['namelist']));
            } else {
                echo toc_menu(strtolower(''));
            }
            //or hold it in a variable to display later on

                ?>
//and this is my page_number codes:
<?php if ($offset>=1) 
    { // bypass PREV link if offset is 0
        $prevoffset=$offset-$limit;
        print "<a href=\"".htmlentities($_SERVER['PHP_SELF'])."?offset=$prevoffset&searchfile=$search&namelist=$listname\"/>Prev</a> &nbsp;";
    }
    echo '</td>
            <td colspan ="5" height ="20" align="right"';
    // check to see if last page
    if (!($offset+$limit > $total))
    {
            // not last page so give NEXT link
            if ($offset == 1) 
            {
                $newoffset=$offset+($limit-1);
            } 
            else 
            {
                $newoffset=$offset+$limit;
            }
            print "<a href=\"".htmlentities($_SERVER['PHP_SELF'])."?offset=$newoffset&searchfile=$search&namelist=$listname\">Next</a> &nbsp;";
    }   
    ?>

TAKE NOTE:
My variable namelist is used for the A-Z variable
the searchfile is for my search button
MisaChan

  • 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-22T19:10:26+00:00Added an answer on May 22, 2026 at 7:10 pm

    After struggling with this long piece of code the only thing that i see that can be causing an issue is $listname

    if listname is not a letter your code will not work.

    here is what i suggested, since your code is not sorted alphabetically you should consider using numbers instead. A-Z will be 1 to 10 or 1 to total pages it makes much more sense,

    here is a class that i use to handle pagination easily

        class Pagination {
    
                public $current_page;
                public $per_page;
                public $page_count;
    
                public function __construct($page=1,$per_page= 15, $total_count=0) {
                        $this->current_page = $page;
                        $this->per_page = $per_page;
                        $this->total_count = $total_count;
                }
    
                public function offset() {
                        return ($this->current_page -1)* $this->per_page;
                }
    
                public function total_pages () {
                        return ceil($this->total_count/ $this->per_page);
                }
    
                public function previous_page () {
                        return $this->current_page -1;
                }
    
                public function next_page () {
                        return $this->current_page +1;
                }
    
                public function has_previous_page () {
                        return $this->previous_page() >= 1? true : false;
                }
    
                public function has_next_page () {
                        return $this->next_page() <= $this->total_pages()? true : false;
                }
    
    // edit this section to suit your needs
                public function format_output ($link,$query) {
                        if ($this->total_pages() > 1) {
                                $output = "<div id=\"pagination\"><p>";
                                $output .= ($this->has_previous_page())? ("<a href=\"/$link/".$this->previous_page()."/{$query}\" >Previous</a>"): "";
                                $c = $this->current_page;
                                $t = $this->total_pages();
                                for ( $i = 1; $i <= $t; $i++ )
                                {
                                        if ($this->current_page == $i) {
                                                $output .= " <a class=\"active\" href=\"#\" >{$i}</a> ";
                                        }else {
                                                $output .= " <a href=\"/$link/{$i}/{$query}\" >{$i}</a> ";
                                                //$output .= " <a href=\"$link?q={$query}&page={$i}\" >{$i}</a> ";
                                        }
                                }
                                $output .= (($t ==$this->total_pages())?"":' ... ');
                                $output .= ($this->has_next_page())? ("<a href=\"/$link/".$this->next_page()."/{$query}\" >Next</a>"): "";
                                $output .= "</p></div>";
    
                        }else {
                                $output = "<div id=\"pagination\"><p>Displaying all results.</p></div>";
                        }
                        return $output;
                }
        }
    
        ?>
    

    and here is how i use it.

    // your listname in numbers
    $currentPage = isset($_GET['currentPage'])? $_GET['currentPage']: 1; // page number 
    $limit =2; // you decided to limit 2 per page
    $total = 10; // the total result available in all pages
    
    $pagination = new Pagination($currentPage, $limit,$total);
    
    // if you need the the value of how many to offset for the current page
    $offset = $pagination->offset(); // example page 6 will return 12
    
    // and to display the pagination simply echo this
    echo $pagination->format_output(htmlentities($_SERVER['PHP_SELF']),'other values u want to pass');
    

    This will automatically create the previous and next button for you

    I hope this will help you solve your problem

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a debugger visualizer in VS2008. There are two classes i've made,
Assume I have created a compiled re: x = re.compile('^\d+$') Is there a way
I have created custom MembershipUser, MembershipProvider and RolePrivoder classes. These all work and I
Using VB6, I have created an Outlook plugin, that has a property page. The
I have created this little program to calculate pi using probability and ratios. In
I have created a certain class to represent an object. My program has several
I have created a program in c++ that doesn't have any GUI. When this
I have created a program which takes a text file full of 3 letter
I have created a C# program that can dial a phone. Now what I
I have created a complex sql server 2008/coldfusion search page, that searches thru a

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.