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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:31:38+00:00 2026-05-25T09:31:38+00:00

I am using PHP/MySQL, to generate a counter code for the each entry while

  • 0

I am using PHP/MySQL, to generate a counter code for the each entry while opening the entry screen.

Here is the code I am using

$qresult = $db->query("SELECT count(*) FROM ap_aurora_projects");
$row = $qresult->fetch_row(); 
$slno = $row[0] + 1;

$today = date("ymd");

$code = $today . "-" . $slno;

This code is generating correctly and showing to user before he creates the record. The issue is when multiple users open same time the code is duplicating in their screens.

What is the method to avoid the duplicates.

I tried to create a separate table to store the latest number and incremented for each request, but the issue is, if user cancel the entry, that number is missing.

EDIT

The code is working properly when one user generate the code and insert the record. But the issue is if multiple users opens simultaneously it generates same number to them in their screen. If all of them try to save the record it is getting duplicated.
Please note that, I generate this number and show in the entry screen initially not while saving the record.

  • 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-25T09:31:38+00:00Added an answer on May 25, 2026 at 9:31 am

    I suppose the code you show in the question is simplified and you can’t use AUTO_INCREMENT column as suggested by another answer.

    You will need to lock the table for reading until it’s updated. Do the MySQL queries in the following order:

    LOCK TABLES ap_aurora_projects READ;
    SELECT count(*) FROM ap_aurora_projects WHERE ...;
    //Update here ...
    UNLOCK TABLES;
    

    More about locking whole tables can be found here:
    http://dev.mysql.com/doc/refman/5.6/en/lock-tables.html

    If you are using InnoDB storage engine, you can read more about advanced (row) locking and transactions here:
    http://dev.mysql.com/doc/refman/5.6/en/innodb-transaction-model.html

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

Sidebar

Related Questions

Been using PHP/MySQL for a little while now, and I'm wondering if there are
Using php and mysql (and Drupal), I want to generate an index based on
How can I generate graphs and charts from a mysql database using php? I'm
I am using an ExtJS 3.0 grid and generate data from PHP using MySQL.
I am trying to generate a grouped/stratified report using PHP and MySQL. tbl_items has
i am using php,mysql,jquery. My case is that step 1 : i generate 10
I am using Mysql and PHP to generate XML which is consumed by a
I am currently using PHP/MySQL and the jQuery timeago plugin. Basically, I need to
Im trying to create a iPhone Objective C login page using PHP/MySQL to authenticate.
Using PHP and MySQL, I have a forum system I'm trying to build. 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.