Create unique ID
Posted: Mon May 12, 2008 7:16 pm
~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:
Posting Code in the Forums to learn how to do it too.
Hello
This is my first post here at phpdn. Hope I'll make it right. Now to my problem.
I wan't to create a unique ID and save it down to my MySQL. The problem is that I don't now how to make the code loop. I'll post my code with explanation.
~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:
Posting Code in the Forums to learn how to do it too.
Hello
This is my first post here at phpdn. Hope I'll make it right. Now to my problem.
I wan't to create a unique ID and save it down to my MySQL. The problem is that I don't now how to make the code loop. I'll post my code with explanation.
Code: Select all
function slumpa() {
$s = chr(mt_rand(97, 122)) . chr(mt_rand(65, 90));
for ($i=0; $i<20;$i++) $s.= mt_rand(0, 9);
return $s;
}
$regid = slumpa()
$sql = "SELECT COUNT(hashid) FROM medlemmar WHERE hashid='{$slumpa}'";
$result = mysql_query($sql);
if (mysql_result($result, 0) > 0) {
// Find a new unique ID and check if it is in the databas, if it is, make this until finding a unique one.
}~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: