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 8643383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:01:17+00:00 2026-06-12T12:01:17+00:00

My apologies if this is the wrong site for this problem, as it is

  • 0

My apologies if this is the wrong site for this problem, as it is more math-related than programming.I am trying to write a series of 7 page links, in a Google-esque fashion. Essentially, it will be 7 numbers, where s is my starting value. I am having trouble calculating my starting value.

In advance, the maximum value in the series is variable depending on the search terms provided by the user, it could be less than, greater than or equal to 7. In my formula-writing attempts, I have been calling this value g. I also know the page number the user has selected. I have been calling this value p So, for example, if g was 21, I would need to generate these series of numbers, where the bolded number is equal to p:

1 2 3 4 5 6 7

1 2 3 4 5 6 7

1 2 3 4 5 6 7

1 2 3 4 5 6 7

4 5 6 7 8 9 10

5 6 7 8 9 10 11

15 16 17 18 19 20 21

As long as I can determine the starting value using the information available, everything else falls into place. Can anyone advise on how I would calculate my starting value using the information available? If it is relevant, I will be writing this formula in PHP.

  • 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-06-12T12:01:18+00:00Added an answer on June 12, 2026 at 12:01 pm

    Suppose you want $n links and $g is the number of pages, in your case $n = 7, the the starting value $s can only range from 1 to $g - ($n - 1).

    In general, when you are not outside these limits the starting value $s is related to the page number by $s = $p - floor($n / 2).

    Putting all this together into a PHP function you get:

    // $p -- user's current page
    // $g -- total number of pages
    // $n -- number of links
    function start_link($p, $g, $n)
    {
        $s = $p - floor($n / 2);
        if($s < 1)
        {
            return 1;
        }
        $max_s = $g - ($n - 1);
        if($s > $max_s)
        {
            return $max_s;
        }
        return $s;
    }
    

    You can test this function as follows:

    print start_link(1,21,7) . "\n";
    print start_link(2,21,7) . "\n";
    print start_link(3,21,7) . "\n";
    print start_link(4,21,7) . "\n";
    print start_link(7,21,7) . "\n";
    print start_link(8,21,7) . "\n";
    

    This will print the start pages of example sequences you gave in your question.

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

Sidebar

Related Questions

I'm writing my first iPhone app and, apologies, if this is the wrong forum
Apologies if I've got the terminology wrong here—I can't think what this particular idiom
Unsure if this should be on here or serverfault so apologies if I'm wrong.
Apologies if this is the wrong overflow to be posting this question to. There
apologies if this is redundant, I spent a good deal of time trying to
I'm new to Python so my apologies if this is something obvious. I'm trying
First off i'm new to Linux programming so apologies if this makes no sense
I apologise if this is on the wrong StackExchange site. I suppose it could
Apologies if this a newbish question, but I'm new to Mac programming, and thought
Apologies if this seems like I want my problem saved for me, but I

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.