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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:41:02+00:00 2026-05-26T06:41:02+00:00

I decided back when I was coding to have different tables for each type

  • 0

I decided back when I was coding to have different tables for each type of content. Now I am stuck solving this. Basically my notification system ranks the newest content by its timestamp currently. This is inaccurate however because there is a small chance that someone would submit content at the same time as another person, and incorrect ranking would occur.

Now if I had all my content in a single table, I would simply rank it by an auto-incrementing variable. Is there a way to implement this auto-increment integer across multiple tables (e.g. When something is inserted into table1, id=0, something is inserted into table2, id=1). Or do I have to recode all my stuff into a single table.

NOTE:

The reason I have content in multiple tables is because its organized and it would reduce load stress. I don’t really care about the organization anymore, because I can just access the data through a GUI I coded, I’m just wondering about the load stress.

EDIT:

I’m using PHP 5 with MySQL.

  • 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-05-26T06:41:02+00:00Added an answer on May 26, 2026 at 6:41 am

    You can create a table with auto increment id just to keep track of ids. Your program would do an insert on that table, get the id, use it as necessary.

    Something along the lines of:

    function getNextId() {
        $res = mysql_query("INSERT INTO seq_table(id) VALUES (NULL)");
        $id = mysql_insert_id();
        if ($id % 10 == 0) {
            mysql_query("DELETE FROM seq_table");
        }
        return $id;
    }
    

    Where seq_table is a table that you’ve to create just to get the ids. Make it a function so it can be used whenever you need. Every 10 ids generated I delete all generated ids, anyway you don’t need them there. I don’t delete every time since it would slow down. If another insert happen in the meantime and I delete 11 or more records, it doesn’t affect the behaviour of this procedure. It’s safe for the purpose it has to reach.

    Even if the table is empty new ids will just keep on growing since you’ve declared id as auto-increment.

    UPDATE: I want to clarify why the ID generation is not wrapped in a transaction and why it shouldn’t.

    If you generate an auto id and you rollback the transaction, the next auto id, will be incremented anyway. Excerpt from a MySQL bug report:

    […] this is not a bug but expected behavior that happens in every RDBMS we know. Generated values are not a part of transaction and they don’t care about other statements.

    Getting the ID with this procedure is perfectly thread safe. Your logic after the ID is obtained should be wrapped in a transaction, especially if you deal with multiple tables.

    Getting a sequence in this way isn’t a new concept, for instance, the code of metabase_mysql.php which is a stable DB access library has a method called GetSequenceNextValue() which is quite similar.

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

Sidebar

Related Questions

I have decided to get back into flash development, and when I last left
I've decided to get back into LISP (haven't used it since my AI classes)
I decided to learn C++ (I program in C at work), and I have
We decided to use the minimumRequiredVersion in our clickOnce application manifest, and now when
I decided to teach myself assembly language. I have realized that my program will
I have decided to use ASP.NET MVC to develop multi page (registration) forms in
Back learning after silly life issues derailed me! I decided to switch my learning
I decided to get back to Cocoa/Objective-C programming recently and my current project calls
Update : Been some time. But back then decided not to use Mongoose. Main
So I’ve been working on this project at work where I’m coding a php

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.