0

I am creating a job number system that a few users will be using at the same time. I have created a job number on the php page and then it saves the number to the job sheet and uses this to link other tables to the job. I take the job number from a table called numbers which then should increment the number by 1 each time the job is submitted ready to create the next job. But the numbers are not working correctly. As an example I get 1,2,3,4,8, then 43,44,45,then 105 I cant see why they would jump so much

$job_number_query = "SELECT * FROM numbers";
            $job_result =($mysqli-> query($job_number_query)) ;
            $job_num = mysqli_fetch_assoc($job_result);
            $increment_job_number = $job_num[job_number];
            $update_job_number_query = "UPDATE numbers SET job_number = $increment_job_number +1 ";     
            $mysqli-> query($update_job_number_query);
            //echo ($customer_id);

Then I simply insert the $increment_job_number into the jobsheet table.

I am using int for the Job_number field in the table numbers I cant think of a way to test the numbers. I guess a way is to look through the jobsheets and add another number to there but because more than one user might have a job that hasn't been submitted yet would this also cause problems.

1
  • Why not just use an auto incrementing field as the job number Commented Aug 19, 2015 at 19:33

3 Answers 3

1

Just increase the value without the first SELECT:

UPDATE numbers SET job_number = job_number +1 
Sign up to request clarification or add additional context in comments.

Comments

0

You have no where clause on your update query, so you're incrementing the job_number field in ALL records in the table.

Comments

0

It was me that was the technical failure in the end. I have got the incremental numbers on the create page but then unfortunately I had also got the incremental number on the edit pages so every time I edited the pages I then added 1 to the number field in the numbers table.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.