Reputation: 2914
I want to make a URL shortener that has this URL format: http://myurlshortner.com/{id}
Where the id is unique and generated from the following place-value notation sequence/system/series:
0
1
2
.
.
.
9
a
b
c
.
.
.
z
For example: http://myurlshortner.com/1b6z
For saving the entry to database, I want to make id the primary key(or unique field) that increments with every new entry and follows the above mentioned sequence. How can I do this?
For data storage, I will use Amazon SimpleDB. So there won't be any stored procedures or other DBMS functionality like there are in MySQL that I can use.
This is exactly(almost) like how URL shortners like http://tinyurl.com and http://bit.ly work.
...and I am coding in PHP. I hope you understand my question.
Upvotes: 0
Views: 183
Reputation: 3520
You can achieve what you want by just converting a normal base 10 id to base 36.
Base 36 uses the numerals 0-9 and then the letters A-Z.
You can do the conversion before storing it in the database and use the converted number as the id, or just use a normal base 10 auto increment and do the conversion in your code.
See: http://php.net/manual/en/function.base-convert.php
php > echo base_convert(123456789, 10, 36);
21i3v9
Upvotes: 1