Welcome to WebmasterWorld Guest from 54.226.62.251

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

generating unique number

unique number, php, no same value in database

     

freshfromseo

6:21 am on Feb 15, 2008 (gmt 0)

5+ Year Member



hello,

does anyone know on how to generate a unique number like for example an employee id or student id. that id is unique right, and it doesnt have the same value in the database. please teach me how...tnx

phparion

6:26 am on Feb 15, 2008 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



$c = uniqid (rand (),true);
echo $c;

freshfromseo

7:47 am on Feb 15, 2008 (gmt 0)

5+ Year Member



tnx, but the output is too long. i want to limit the number in 6 digits.

how to do that? please help..

camilord

10:28 am on Feb 15, 2008 (gmt 0)

5+ Year Member



$randNum = uniqid(rand(100000,999999),true);

camilord

10:30 am on Feb 15, 2008 (gmt 0)

5+ Year Member



<?php

$randNum = rand(100000,999999);
echo $randNum;

?>

whoisgregg

2:10 pm on Feb 15, 2008 (gmt 0)

WebmasterWorld Senior Member whoisgregg is a WebmasterWorld Top Contributor of All Time 10+ Year Member



If you set an auto incrementing field in your database, you can just do an insert (with that value set to null) then use mysql_insert_id() [php.net] to find out what number was assigned by MySQL.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month