vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Random Number, if duplicate? (https://vborg.vbsupport.ru/showthread.php?t=107564)

Red Blaze 02-09-2006 06:45 PM

Random Number, if duplicate?
 
Code:

<?php
srand ((double) microtime( )*1000000);
$random_number = rand( );
echo "$random_number";
?>

I want to use this random code generator, to store in the database a code. I want this number to be unique. How can I keep PHP from duplicating a code saved in the database?

I can tell MySQL to keep it unique, but I don't want an error page. I want to keep errors to a minimum. Thank you for the help.

I was thinking of a loop to check if it exists until it finds a unique number and end the loop before it spits out the page with the code in a hidden field. I just don't know what codes to use. >_<

Marco van Herwaarden 02-09-2006 06:51 PM

What are you trying to do with this?

Red Blaze 02-09-2006 06:55 PM

Well, I want this for a gallery. When someone makes an album, the random number generator would create a number. The user would have to keep this to go back to view the album. Kind of like a passcode... key kinda thing.

Guest190829 02-09-2006 07:00 PM

Why not just use mysql's auto_increment attribute, which adds a unique identifer to table rows?

Red Blaze 02-09-2006 07:03 PM

Well, I don't want single digit keys. Otherwise, random people will just type 1, 2, 3, 4, 5...and have access where they're not suppose to be.

Marco van Herwaarden 02-09-2006 07:07 PM

So you want to make it that anybody that want to view an album needs a password? Or just the original owner of the album when they want to edit it?

Red Blaze 02-09-2006 07:10 PM

If the users types in the correct passcode, they can view the album.

Marco van Herwaarden 02-09-2006 07:16 PM

And how will they get that password?

Wouldn't it be easiest if you let the user who creates the album just let choose a password?

Red Blaze 02-09-2006 07:19 PM

It would be emailed to them.
lol I have it figured out. I just want to know how to keep it from duplicating; if it ever happend.

Paul M 02-09-2006 07:21 PM

Why does it matter if you happen to get a duplicate ?


All times are GMT. The time now is 11:32 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01650 seconds
  • Memory Usage 1,723KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete