Jump to content

Prefixing a Random Number Using 'rand'


DamienRoche

Recommended Posts

Hi guys. I'm having a few problems with this script.

 

$unique_id = rand(100000000,999999999);

 

Everything works (the random number is generated & inserted into MySQL db) but I can't figure out how to prefix the random number with text.

 

I've changed the field the number inserts into in the db to a varchar.

 

I've tried:

 

$unique_id = "prefix"&rand(100000000,999999999); //to no avail

 

Any thoughts?

 

Thanks,

 

Damien.

Link to comment
https://forums.phpfreaks.com/topic/116956-prefixing-a-random-number-using-rand/
Share on other sites

Just sussed it!!

 

I love php <3  ;D

 

Any way, in case any one else is interested..here's how:

 

$unique_id .= "prefix";

$unique_id .= rand(1000000000,9999999999);

 

Notice the period before the equals.

 

Hope this helps someone.

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.