-2

I'm building a website which allows the user to drag elements on to the screen using JavaScript and jQuery. I would like to store these elements inside a database, and then draw them back on to the screen when they visit the website again.

Each element will need a unique id, this will be used when performing a few functions such as addComment(id), editElement(id).

An id count is going to be incremented every time an element is added, and this id count will be assigned to the element which has been created e.g.

  • 1st element id = 1
  • 2nd element id = 2... etc

What would be a secure method of persistently keeping track of this id count? it needs to be used client and server side.

I'm not sure why this is being down voted, it's a pretty clear question.

Solution: I'm going to store the element id's and the total number of elements in a database, each time an element is created an ajax call will be used to assign the id to that element (which will be the element type concatenated with the number of previously created elements) and then store it in the database.

Jack
  • 15,614
  • 19
  • 67
  • 92
  • 1
    Note that IDs should not start with numbers. – karim79 Aug 30 '11 at 11:28
  • store them in a database. Seriously, what is your question? – JMax Aug 30 '11 at 11:28
  • What do you mean by "secure method"? "Secure" as in the same value is being kept client and server side and there can't be any differences ever? Do this id count must be kept per-user or as global count? – WTK Aug 30 '11 at 11:30
  • @Jmax What's wrong with storing the properties of created elements in a database? – Lazarus Aug 30 '11 at 11:31

3 Answers3

1

If you are adding the component to a database then I'd use the identity from the database as the ID (with some kind of prefix, i.e. "component1", "component2", etc). That way your are sure that the value is unique.

Lazarus
  • 41,906
  • 4
  • 43
  • 54
0

Assuming you are saving them in a database, why not just use the auto-increment feature of the database? that way you will have a unique ID for every element in the database.

Another possibility is to use PHP's uniqid() which will output a long random ID for your elements to use.

Madara's Ghost
  • 172,118
  • 50
  • 264
  • 308
0

Use a construction method like TIMESTAMP(date+time(upto - millisecs)) returnning a unique starter ID. add an exta digit, increment it. After that before making ID, append it to a string like CID+timeStampID.

Seriously, i cannot understand what are you trying to achieve. Any way this can generate a unique ID. keeping it is upto you All the best

Kris
  • 8,680
  • 4
  • 39
  • 67