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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T01:48:58+00:00 2026-06-19T01:48:58+00:00

How can I automatically generate a unique, random 6 digit number to insert into

  • 0

How can I automatically generate a unique, random 6 digit number to insert into a column of a mysql table? The randomly generated number must not already exist in the column.

I am accessing mysql via php.

The table format is like so, with the random number going in the reqnumber column:

id,status,reqnumber
  • 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-19T01:49:00+00:00Added an answer on June 19, 2026 at 1:49 am
       function gen(){
        $num = rand(100000,999999);
        if($num == ifnumberinyourdatabase){
        gen();
        }
        return $num;
        }
    

    You can also use recursive function here.
    which check’s if number is your database if it is generate new one if not return the unique number

    function gen(){
            $num = rand(100000,999999);
    $query_idgetrs = "SELECT * FROM servicetbl where reqnumber = $num";
    $idgetrs = mysql_query($query_idgetrs, $dbconnection) or die(mysql_error());
    $row = mysql_num_rows($idgetrs);
    
            if($row >= 1){
            gen();
            }
            return $num;
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Struts 2 automatically generate HTML table for it's <s:form> tag. How can I disable
Is there a tool that can automatically generate class diagrams from Action Script code?
How can I write a program that will automatically generate a sample examination? For
Is there a way I can automatically generate Content-Type headers in .NET? I'm working
I'm running the following MySQL query (trimmed down), generated automatically by MySQL Workbench and
Is there any tool/library which can automatically generate the tests for my hashcode and
When designing the core data model in XCode, you can automatically generate NSManagedObject subclass
I want to automatically generate user accounts by generating a random username and password,
I'm trying to generate a unique dosieid number for my web site. My web
I think opengl can automatically generate mipmap texture, does XNA support this?

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.