[thelist] mysql primary key question..

jcanfield at magisnetworks.com jcanfield at magisnetworks.com
Mon Jul 8 12:28:05 CDT 2002


> 1. so, if i were to really do such a thing in php myself, any
> idea how i would write the logic for creation of these
> strings?

If you're familiar with hexadecimal numbers, this is complex but
understandable. In base 10, our normal numbering system, the far right
placeholder counts up thru all possible values (0-9) then the second
placeholder increments one and the first (far right) loops and starts over
again. Every time the far right place loops, the second increments. When you
finally get to the highest value in the middle column, *it* loops, the far
right loops, and the final/third/left-hand place increments one.

In hex (base 16) you use 0-9, and A-F, which are single character
representations of the numbers 10 through 15. All you need to do is use a
bigger numbering system; use all the ASCII characters instead of 0-9.

And honestly, if that's over your head, step back and rethink this thing.

> 2. if i were to generate all these strings beforehand, and
> put them into a mysql table with number IDs and then tag the
> row as "used" whenever i used one of these, do u think that
> is a good way of doing it? e.g.,

No point writing two million lines to the db when the number could be
generated on the fly, with the right code.

Are you really sure there's no circumventing the three-digit limit on this
field? Seems like we're jumping through a lot of hoops, which tells me that
we may be trying to solve the wrong problem - I think we should be
addressing the field length limit, not trying to invent a new type of
auto_increment.

joel



More information about the thelist mailing list