smc Posted January 29, 2007 Share Posted January 29, 2007 Hello,I'd like to make a random article id that can never re-occur. I thought about doing auto-increment in MySQL but I'd rather not give away exactly how many articles are in the DB, just seems unprofessional.Thanks for any light you can shed on the issue!Thanks Quote Link to comment Share on other sites More sharing options...
HuggieBear Posted January 29, 2007 Share Posted January 29, 2007 How about make it auto-increment but start it on something random like 4932.Nobody will be any the wiser then![code]ALTER TABLE table_name ADD column_name INT UNSIGNED NOT NULL AUTO_INCREMENT=4932[/code]That should do it.RegardsHuggie Quote Link to comment Share on other sites More sharing options...
boo_lolly Posted January 29, 2007 Share Posted January 29, 2007 how many characters do you want it to be? a quick/simple example would be:[code]<?php $salt = ""; $rand = rand(0, 9); $length = 10; for($i = 0; $i < $length; $i++){ $salt .= $rand; } echo $salt;?>[/code]untested. Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 29, 2007 Share Posted January 29, 2007 or use the current timestamp. That's what a legacy program I once had to maintain did. Seriously, no one will care but you... Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted January 29, 2007 Share Posted January 29, 2007 i was going to suggest timestamp to. just use time() or microtime() except microtime() has a decimal in it, but that could be removed. Quote Link to comment Share on other sites More sharing options...
HuggieBear Posted January 29, 2007 Share Posted January 29, 2007 [quote author=ProjectFear link=topic=124605.msg516537#msg516537 date=1170111884]i was going to suggest timestamp to. just use time()[/quote]If you're going with timestamp, then just use mysql's now() function, don't worry about PHP's time() or microtime() functions at all.INSERT INTO table_name (unique_id) VALUES (now())RegardsHuggie Quote Link to comment Share on other sites More sharing options...
smc Posted January 29, 2007 Author Share Posted January 29, 2007 I saw this somewhere, would this work?md5(uniqid(rand())) Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 29, 2007 Share Posted January 29, 2007 That's kind of overkill. Plus md5 can collide. Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted January 29, 2007 Share Posted January 29, 2007 if your going to use md5 just insert the id as like, 1, 2, 3, 4 etc. Then when retriving it and using it md5() the variable. It would be easier to configure your DB in the future. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.