Jump to content

Incident Management System


Ryflex

Recommended Posts

Hi all,

 

I'm starting an new project where I'm making an Incident Management System and right from the start I don't know what to do.

Could anyone get me on my way. I need to make a script where if I open a new incident the new page opens and automatically gets a new Incident number. This number is offcourse 1 number higher every time you make a incident.

I thought about make a column with autoincremetn and then query the highest number. Problem with that is when you open a page at multiple computers at the same time they get the same number.

 

Does anyone have an idea?

 

Ryflex

Link to comment
Share on other sites

The auto-incremented ID is only generated as you actually insert the row, and so no two users could end up with the same ID.

 

Edit

 

Just be clear, you don't need to actually query the table to find the current highest ID. MySQL will automatically generate and insert the number as you insert the row. You don't even need to include it within the columns you list in the insert statement.

Link to comment
Share on other sites

Hi MrAdam,

 

Thanks for the quick reaction!

 

Well in my idea when you open the new incident page you create the new row and query it. That is because when I open the page I want the Incident number to automaticaly show.

 

Ryflex

Link to comment
Share on other sites

So you want to create a new, blank incident as soon as they click create? The problem I can foresee there is  that the user may leave the page, have clicked create by accident,  etc. You'll end up with blank records that sooner or later you're going to have to purge. Of course, the severity of that depends upon the size of the organisation this is for, or whatever you plan to do with it.

 

Anyway it's perfectly possible to do what you want, but you will need to insert the blank row (which means you'll need to allow null values for every column) to guarantee the user gets the incident number you display.

Link to comment
Share on other sites

Hi MrAdam,

 

I wil make another script which will run everyday and delete blank records.

My big question with the solution I have won't 2 users end up with the same number because the clicked create at the same time.

Link to comment
Share on other sites

Nope. MySQL uses table-level locking during an insert, to prevent issues like that. Even if they both fired at the very same millisecond, only one insert would be performed at a time whilst the other waited. Afterwards you can use the mysql_insert_id function to retrieve the ID that was created.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.