Reputation: 61
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.
Upvotes: 0
Views: 76
Reputation: 61
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.
Upvotes: 0
Reputation: 7722
Just increase the value without the first SELECT:
UPDATE numbers SET job_number = job_number +1
Upvotes: 1
Reputation: 360572
You have no where
clause on your update
query, so you're incrementing the job_number field in ALL records in the table.
Upvotes: 0