Jump to content

How to create an 8 digit unique and random number for each posting in php


kee2ka4

Recommended Posts

Hey peeps,

 

I wanted to create a Random and a Unique Number of 8 digits that will represent each unique advert posted by users. I have an advert_id in the database that is the primary key but I do not want to use that on the site for security reasons. So each advert_id will have a unique 8 digit number which will be stored in the table under column name Ad_num. Could anyone guide me how to do this.

 

The 8 digit number has to be unique and random and no fields in the database can have the same number.

 

Thanks,

Zub

Thanks for your reply, The only problem with timestamp value is that it gives 10 digits but I guess I can do with that. I think if I also add the advert_id to the value it will be certain that it will give me a unique number. Can the time() function ever give the same timestamp value?

A random number is not unique. Roll the dice, each roll is a random number.  But you will often get the same number repeating.  That is part of randomness.

 

You want to create a unique number.  Start with a number and increment it.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.