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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:49:57+00:00 2026-06-10T10:49:57+00:00

What I have is a table with elements. Each element has a unique id

  • 0

What I have is a table with elements. Each element has a unique id and a unique short id, called short. It looks e.g. like the following:

id=>short
1 => 1
9 => 9
10=> a
37=> B

etc. The short ids are generated via a php function.

what I want to do now is letting the user set his own custom short.
Let’s say the 38th user wants his short to be “foobar”. The easy solution would be:

10=> a
37=> B
38=> foobar
39=> D

But that way I gonna lose the C . And if many usersdecide to use a custom short id, that will end up in many short ids lost.

So each custom short will cause the id to be “too far ahead” is there any way to fix this issue? either in mysql or php.

Perfect would be:

10=> a
37=> B
38=> foobar
39=> C
40=> FUBAR
41=> D

Update: (possible triple row approach)

row “used” only increases, when the short id was generated and not custom made. This way the short ids can always be generated using the “used” row. e.g. :

id  |  short  |  used
10  |  a      |  10
37  |  B      |  37
38  |  foobar |  37
39  |  C      |  38
40  |  FUBAR  |  38
41  |  D      |  39
  • 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-10T10:49:59+00:00Added an answer on June 10, 2026 at 10:49 am

    Should be simple enough.

    1. Create a new table with recycled short ids

    2. Create another (sequence) table that holds the last id used for short id generation

    3. When a short id gets replaced by a custom one, insert it into the recycling bin

    4. When you need to create a new short id, look in the recycling bin first.

      a. if you can find an item, use that as the new short id (and remove it afterwards)

      b. if the bin is empty, increase the sequence by one and generate a new short id from that.

    Update

    This is a simple way to create and use sequence tables:

    CREATE TABLE seqname (id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY) ENGINE=MyISAM SELECT 0 AS id;
    
    UPDATE seqname SET id=LAST_INSERT_ID(id+1);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table where each row has 13 TD elements. I want to
I have a table that assign elements to groups. Each element can exist in
I have a hierarchical structure stored in a table. Each element has a pointer
I have an HTML table in which each data row has a unique id
Suppose I have an array that mimics a database table. Each array element represents
I have the following Table elements how do i run a query that reproduce
My application is in ASP.net MVC3. I have a table of elements. An element
I have a table that has a column that contains links. Each cell in
I have a table which each td has title, id, and lang attributes. I
I have a table of items, each of which has a date associated with

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.