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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:20:48+00:00 2026-06-13T04:20:48+00:00

Currently I have a working application but I would like some advice because I

  • 0

Currently I have a working application but I would like some advice because I feel like there must be a better solution. One of the features on the site I am building is a feature to show users videos when they search for them. The search would be done by clicking a link like "View All Dreamweaver Tutorials" Each page in the search has a max of 12 videos and if the search has queried more then that you can click a link to go to other pages. Again, all works fine but I am not a fan of my logic and would like to hear if anyone has a better solution to a very common task.

Here’s an example of parameters I might send when the user clicks a link …

search?tag=Dreamweaver&sub=CSS&page=1

Where tag is the main category, sub is the sub category, and page is the current page they would like to see. If the user gives a page that is out of bounds they are directed to a special screen. So if the servlet saw

search?tag=Dreamweaver&sub=CSS&page=1000

It would redirect the user!

Now, here’s a bit of my servlet that grabs these parameters that are sent …

category = request.getParameter("tag");
subCategory = request.getParameter("sub");
page = Integer.parseInt(request.getParameter("page"));

ArrayList<Integer> startStop = Page.getPageStartStop(page);
int start = startStop.get(0);
int stop = startStop.get(1);

videoList = SearchDAO.getSearchResults(category, subCategory, start, stop);

Here is where I do not like my logic. As you can see I first grab the parameters. Fairly normal. But then I call a method in the Page class and send it the page number parameter. So for this example I would be sending the number 1. Then the purpose of that method is to figure out through if statements the start and stop points that the database should query. So that method looks something like this.

public static ArrayList<Integer> getPageStartStop(int page)
{
    ArrayList<Integer> startStop = new ArrayList<Integer>();

    if (page == 1)
    {
        startStop.add(0);
        startStop.add(12);
        return startStop;
    }
    else if (page == 2)
    {
        startStop.add(11);
        startStop.add(23);
        return startStop;
    }
        ......
}

So for the example if page 1 being sent, the method returns 0 for start and 12 for stop and sends those values to my DAO so that the query knows where to start and where to stop. Below is a snippet of my DAO and the last two questions marks become my start and stop.

preparedStatement = connection.prepareStatement("SELECT * FROM videos WHERE category = ? AND subCategory = ? LIMIT ?,?");

So the problem is that Page class needs a lot of if statements to anticipate pages and return their result. Can anyone else think of a better way to do this. Maybe a common algorithm? So many websites utilize this functionality so I know there must be a cleaner way to carry out this problem. It was honestly just the first thing that jumped into my mind. Thank you so much for reading! Comments and answers would be greatly appreciated!

  • 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-13T04:20:49+00:00Added an answer on June 13, 2026 at 4:20 am

    Maybe you can do something like this

    private static int ITEMS_PER_PAGE = 10;
    
    public static List<Integer> getPageStartStop(int page) {
        int start = ITEMS_PER_PAGE * (page-1); // will return 0 for page 1, 10 for page 2, etc...
        int stop = (ITEMS_PER_PAGE * page) + 1; // will return 11 for page 1, 21 for page 2, etc...
    
        return Arrays.asList(new Integer[] { start, stop });
    }
    

    And indeed, this is called pagination.

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

Sidebar

Related Questions

I currently am working on a legacy application and have inherited some shady SQL
I have a project i am working on currently and would like to implement
I have a working JQM application that I'd like to display some images in.
I am working on splitting out an existing, working application that I currently have
I am working on a Facebook application and am currently trying to have my
I'm currently working on web application using VB in ASP.NET. Right now I have
I'm currently working on a simple web application where users each have their own
I am currently working on MVC4 SinglePage Application. I have a Web Api method
I'm currently working on an oophp application. I have a site class which will
I'm currently working out the layout of a WPF Application and seem to have

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.