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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:08:15+00:00 2026-06-12T01:08:15+00:00

Context I’m working on a small web app to store photos. Photos are ordered

  • 0

Context

I’m working on a small web app to store photos. Photos are ordered according to their timestamp (the date they’ve been taken), and it’s working great. Here’s a simplified look at the database:

+--------------+-------------------+
|      id      |     timestamp     |
+--------------+-------------------+
|       1      |    1000000003     |
|       2      |    1000000000     |
+--------------+-------------------+

Now I’d like to add the possibility to re-order photos. And I can’t find a way of doing that without any downsides.

What I did

I first added a column to the table to save a custom order.

+--------------+-------------------+-------------+
|      id      |     timestamp     |    order    |
+--------------+-------------------+-------------+
|       1      |    1000000003     |      1      |
|       2      |    1000000000     |      2      |
+--------------+-------------------+-------------+

First issue: I believe I can’t order photos according to two different criteria, because it’d be hard to know which one has to be given precedence.

So I’m ordering them using the order column, and only this one. When I added the order column, I gave each photo a value so that the current order would remain. I now have photos ordered by order, in the same order as when they were ordered by timestamp.

I can now re-order some photos manually, and the other ones will stay where they belong. The first issue has been solved.

But now, I want to add a new photo.

Second issue: I know when the new photo I’m adding has been taken, but my photos aren’t ordered by their timestamp anymore. This photo needs to be correctly ordered, thus it needs a correct order value.

This is the issue: a correct order value.

Here are two ways I could handle a new photo:

  • Give it an order value greater than others. In the previous table, a new photo would be given order = 3. This is obviously a bad idea, since it doesn’t take its timestamp into account. A recent photo would still be the last one displayed.
  • "Insert" it where it belongs, according to its timestamp. Looking at the same table, if the timestamp of the new photo was 1000000002, the new photo would be given order = 2, and the order of every following photo would be increased by 1.

The second solution looks great, except in one case: if the order of the photo #2 had been manually changed to let’s say 50, the new photo would have been given order = 50 even though it belongs among the first photos (according to its timestamp).

What I need

What I need is a way of ordering photos according to their timestamp and to their manually-set order.

Maybe you have a solution to the second issue I highlighted, or maybe you’re aware of a whole other way to deal with this. Either way, thank you for your help.

  • 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-12T01:08:16+00:00Added an answer on June 12, 2026 at 1:08 am

    At no point in your question do you mention computers or programming languages. This is OK (actually, it’s a good approach, get the problem and solution worked out on paper before coding) and here’s an answer which also ignores computers and programming languages.

    Put all your photos into a shoebox in the order in which you get them.

    Now, take three pieces of paper:

    On page 1 write the numbers (one to a line) from 1 to N (the number of photos the box can hold). Whenever you put a photo in the box, write its timestamp on the line corresponding to its order in the box.

    On page 2 write the timestamp of photo 1 a few lines down. Write a 1 on the same line. For the next photo, write its timestamp in the appropriate place on the paper, leaving as much space above and below as seems necessary for future photo insertions. Write a 2 on the same line. Continue until you run out of space between lines, when you need to copy all the information onto a new version of the page with more space for insertions. The information on this page is the same as the information on page 1, but with the two numbers on each line swapping positions.

    On page 3 write the numbers from 1 to N again. As you collect each photo write its number from page 1 (ie its number in the sequence of all photo numbers) in the correct position for your manually-set ordering. You’ll probably have to do a lot of rubbing-out and re-writing on this page as you decide that latecomers ought to be inserted high onto this page.

    Now you have:

    • a store for your photos, the shoebox; you should already have realised that you can’t store the photos in more than one order at a time;
    • three indexes (indices if you prefer); the first is fixed and simply assigns a unique sequence number to each photo; it also tells you the timestamp of each photo in the box;
    • the second index enables you to find the unique sequence number of a photo given its timestamp, and then find the photo in the shoebox;
    • the third index allows you to order photos as you wish; the first number on each line is the sequence number in the sorted order, the second number is the photo’s unique sequence number from the first index.

    All of this is an extremely long-winded way of telling you that, since you can’t (either in a shoebox or a computerised data store) keep photos in multiple orders simultaneously, you will have to maintain indices for the orderings you wish to use. Those indices point (that’s what an index does) from a number to a location in the shoebox, either directly or indirectly.

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

Sidebar

Related Questions

Context: As a personal learning project I've been working on a simple computer algebra
Context: I'm working on the design of a Project that involves a web client
Context Clojure Agents are NOT sent new values. They are sent a function which
Context I want to use JavaFx with clojure. I am aware of http://nailthatbug.net/2011/06/clojure-javafx-2-0-simple-app/ Question:
Context: I'm working on exercises in Software Foundations . Theorem neg_move : forall x
Context: .NET web service deployed on local IIS in XP. VS 2010 used to
Context: I have a clojure-based crossword app whose main ui is a JTabbedPane with
Context: budget tracking app which will have lots of receipts belonging directly to a
context.EntitySet.AsEnumerable().OrderBy() returns an IOrderedEnumerable which is guaranteed to be ordered but it looks like
Context: single page web applications written in JavaScript and AMD modules (like require.js) What

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.