homepage Welcome to WebmasterWorld Guest from 23.23.57.144
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
generating unique number
unique number, php, no same value in database
freshfromseo

5+ Year Member



 
Msg#: 3575487 posted 6:21 am on Feb 15, 2008 (gmt 0)

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

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 3575487 posted 6:26 am on Feb 15, 2008 (gmt 0)

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

freshfromseo

5+ Year Member



 
Msg#: 3575487 posted 7:47 am on Feb 15, 2008 (gmt 0)

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

how to do that? please help..

camilord

5+ Year Member



 
Msg#: 3575487 posted 10:28 am on Feb 15, 2008 (gmt 0)

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

camilord

5+ Year Member



 
Msg#: 3575487 posted 10:30 am on Feb 15, 2008 (gmt 0)

<?php

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

?>

whoisgregg

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



 
Msg#: 3575487 posted 2:10 pm on Feb 15, 2008 (gmt 0)

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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved