PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
~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.
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: Posting Code in the Forums to learn how to do it too.
Hello and thanks for the answer! Yes I know the auto_increment "method" but I need it to be this way I explained. It should be a hash in a login function and every user should have a unique one.