/    Sign up×
Community /Pin to ProfileBookmark

Need to generate unique name… nanoseconds?

Hi I’m displaying images from a mysql query onto a page. Each image is a submit link for a form. Each form has to have a unique name, or its submit function will not work when clicked. So I made the form names equal to the image filenames.

This is not working because sometimes images are displayed more than once per page (this is the way it’s supposed to work). So I tried making the form names equal to “filename(current_time_in_microseconds)”. But the script is too fast for that and all the form names end up with the same value for “current_time_in_microseconds”, still leaving open the possibility for duplicate form names where there are duplicate images.

So how might I go about doing this? If I could find a way to do it with time somehow that would be ideal, because I would have to worry about tracking how many total images (and forms) had been printed to the page. I’m knee deep in nested functions you see, so that would mean passing a bunch of variables I’d like to try to avoid.

So, I’m pretty sure from what I’ve read that PHP will only do microseconds, and not nanoseconds. Is this correct? And can anybody think of a simple way to accomplish this?

Thanks for any input,
== Matt

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@scragarDec 31.2008 — http://php.net/uniqid

There is a function to be used for unique values.
Copy linkTweet thisAlerts:
@mmsengauthorDec 31.2008 — Brilliant. Many thanks.

Gotta love PHP. If you want something done...

it's already done, you just look up the function name ?
×

Success!

Help @mmseng spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...