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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:12:54+00:00 2026-06-11T17:12:54+00:00

I am trying to generate a list of elements : red green orange blue

  • 0

I am trying to generate a list of elements :

  • red
  • green
  • orange
  • blue
  • yellow+

In that case orange is selected and I have the two elements before and the two elements after.

How can I get this list from a MySQL query?

An example of a table :

5 – A


1 – B


4 – C


8 – D


7 – E


9 – F


3 – G

  • 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-11T17:12:55+00:00Added an answer on June 11, 2026 at 5:12 pm

    I finally did it with an application code :

    def get_list_queryset(self):
        STEP = 5
        LIST_SIZE = 2*STEP+1
        current_object = self.get_object()
        query_set = list(self.model.objects.order_by(*self.model._meta.ordering))
        index = query_set.index(current_object)
    
        # Index too close to start
        if index < STEP:
            start_ind = 0
            end_ind = LIST_SIZE # We don't care if it's too big.
        # Index too close to end
        elif index+STEP >= len(query_set):
            end_ind = len(query_set)
            start_ind = end_ind>=LIST_SIZE and end_ind-LIST_SIZE or 0
        else:
            start_ind = index-STEP
            end_ind = start_ind+LIST_SIZE
    
        return query_set[start_ind:end_ind]
    

    The answer is that MySQL is not good to handle that, so it is more flexible to do it in the application.

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

Sidebar

Related Questions

I'm trying to write a function that will produce the combinations of list elements
I'm trying to generate a query that finds all large, red things with a
I am trying to generate a list of all possible number combinations within a
I'm trying to generate a list dynamically from database. The results can be retrieved,
I am new to clojure and am trying to simply generate a list with
I'm trying to generate a top ten list of locations according to my MySQL
I'm trying to generate an XML document from C# List. The xml document must
I have this code that does the following: -generates a linked list that contains
I'm trying to generate form elements with jQuery to send to a Paypal form,
I have several XML files that I need to generate Ruby code for. The

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.