Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




Generate A Random Number & Check DB To See It Is Unique


I have a registration form that once submitted inserts the values into a mysql db. Its a registration form for a trade account (eCommerce site) - basically once a company applies for a trade account, i'd like an Account Number to be generated automatically however obviously this needs to be unique.

So ideally i'd would like it to randomly generate an 8 digit number and then check the database to ensure it isn't already in use.




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Generate Random Id / Unique Id
I am creating an affiliate system for a website and am a bit stuck as to how to generate a unique id for each affiliate when they register.

In my mysql table I will have a unique 'id' (auto inc) and I then want to have an affiliate_id column. Can I get the DB to give auto increment the id numberr using these letters beforfe the id number 'aff-'

example:

aff-1
aff-2
aff-3

Or should I use php to generate this?

Generate A Unique Number
i have a screen where there is a field called patient #. this is a text write in field. this field should already display a number(can be anything - alphanumeric) when page loads. user can either retain the same number or type in another number on top of it and hit submit to retain whatever was chosen.

is there a way we can auto-generate a number( a function or something like that) that i can use to populate this field? at  this time, user can only enter a number(all numerics) in this field. i should let them either write in their number or keep the system generated number.

How To Generate Random Number
i want to generate a string which contains 5 characters and all 5
characters are randomly generated means it is not fixed that which
string i will get after i execute function.

so tell me random number generation in php

Generate Random Number Daily.
how to program in php and for a site I am making I need to create a script that generates a random number every day. I have written this so far and unfortunately it is not giving me the results I need. Code:

Random Unique Number - Joint MySQL
It has been asked of me to create a randomised unique number. I have generated the random number, however I want to make it unique by cross referrencing the database. IF the number has already been stored it shall REPEAT the function until the new random number is not in the database. When it is unique it shall then be stored in the database. Code:

Generate Random Userid
I'm trying to do some marketing research and I am looking to track which pages users go to and where they leave.

On every link I have something like this <a href='somepage.php?pageid=about_us?userid=$randuserid

and follow the user on the site. How would I generate  $randuserid = (Random Number).

Generate Random Questions
I would like to generate ONE question for a user whenever he visits my page. The questions r stored in the database. And the user will hv to enter his email which is stored in the database. If the email is entered the second time, a different question will be given.

so my question is, how do i make sure that the same question will not b repeated if the same email is entered? any suggestions?

PHP To Generate A Random Bingo Card
I may have mentioned that I run an Introduction to PHP course at a local
college (very basic - I'm no PHP expert). Well, one of my students was
doing really well so I set him some extension work. The task was to use
PHP to generate a random bingo card. The standard UK card has nine rows
and three columns. Each row has five numbers. All numbers are
different, out of a pool of 90.

I asked my student to design one card. He came back a few days later
with a solution that generated six cards, using each of the90 numbers
just once. Or so I thought.

Although I'd set the problem I had not coded the solution myself so I
set to it. I tried various methods but could not get a script which
would work reliably every time. More often than not I could not get all
the numbers to fit. I eventually solved the problem by brute force, ie
I discard all attempts that don't work.

Code is here:

I was still smarting because I thought my student had come up with a
better solution than me so I took another look at his. He had the same
problem, occasionally, the last line was not complete. It's a bit like
the card game patience, sometimes it doesn't work out. If you are
reading this Craig, don't look at my solution :-)

The question I have is this. Is it possible to write an algorithm that
will place all 90 numbers in the matrix in a random fashion that will
not have to loop because of failed attempts?

Generate Distinct Random Numbers
I'm trying to build a simple lotto number generator.  I'm having a hard time getting it to not use a number that is has already picked.  I'm thinking I need a recursive function or something  Code:

Generate A 32 Length Random String
I want to generate a 32 length string which contains both number 0-9 and letter A-Z
letters must be caps, any ideas guys?

Generate Random IDs/strings In Classes
Ok, so I've started using php and I am having some problems understanding how classes work. I think the code I have thus far is good, but I am unsure of how to actually call the class functions and make it all work.

Here is what I have so far: .....

Generate 2 Random Numbers In Rapid Sequence
I need to generate 2 random numbers in rapid sequence from either PHP or
mysql.
I have not been able to do either. I get the same number back several times
from PHP's mt_rand() and from mysql's RAND().
any ideas?

I suppose I could use the current rancom number as the seed for the next
random number. but would that really work?

Generate From Number.
I need a good method to generate a random number based on a different number. Here is the code i have now, but it doesn't work. Code:

Username Creation Unique Check
using a simple form to insert data in to mysql URL it will not however check whether the username has already been 'taken' how do I go about coding something like this. I understand that it will be a simple check procedure. If there is already that username then an error message will appear informing them of that. PHP Code:

Auto Generate A Number
I use an online ordering system. Is there a way to automatically generate a random 6+ digit unique number and also print the number on the confirmation page? I dont use mysql or any database. Here is the link for the actual page. You can go ahead and submit something (just use "Test" on the name field) Code:

Generate A Number On Screen...
i have a screen where i register a new patient into the system. way the system works now is that user enters the patient details(first name, middle initial, last name, dob, sex, insuracne, and so on). along with this user also enters the patient # for each patient(its a 9 digit unique number - on the lines of the ssn). the system validates this field upon submittin gthe page. it should contain only numerics ad shoud be 9 characters long. it returns an error message if this field does not match the validations.

the new requirement now is that user should allow (automatically) a number (18 characters - alphanumeric) to be generated when page is loaded. user can either keep this number (system generated) or should be able to enter a new(numeric - 9 digits) when registering a patient. they can come back later and edit it with a proper patient number.

is there a way i can put a check-box or somethign which i can check and then be able to enter alphanumeric value(18 digits) in the same box (used for 9 digit patient number)? Code:

Random Number In PHP
<?php
srand( microtime() * 1000000);
$num = rand(1,100);
echo("Random Number:".$num."<br/>");
?>

Every time, it generates number 1... Why?

Random Number
i am trying to find a random number but keep getting zero here is the code i am using.
PHP Code:

Random Number
<?php 
$_SESSION['point'] = rand(0, 10).".". rand(0, 9) rand(0, 9); 
echo $_SESSION['point'];?>

I want to set a variable (SESSION OR NOT) to a random number. The number needs to be 2 dec places. so i've used 3 random numbers. ??

how can i get it to work? The idea is to add the amount to a mysql cell (easy enough i believe) and then echo the cell out. number should look like this : *.** in the sql table. so: 3.91 or 1.27 etc.

Random Number Generator
<?php
function get_random_number_between($start, $end) {
srand((float)microtime()*1000000);
$random_number=rand($start,$end);
return $random_number;
};
echo get_random_number_between(2, 4);
?>

Could anyone suggest how to modify this code to output a float between 2 and 4 with 2 decimal places?

How Do I Create A Random Number In PHP?
I am working on a project that requires each article to be assigned a unique nine-digit ID number that will be stored in a mySQL database along with some other info. I know I can use the PRIMARY KEY function to make sure it's unique in mySQL but my problem lies in the fact that I don't know how to generate a random 9-digit number in PHP! Can someone please help me out here?

Random Number Function
I was wondering if php4 has a random number function. I want php to pick a random number between 1 and 1000.

Random Line Number
What would be the easiest way to get a random line entry from a text file using file()?

Not Asigning The Random Number!!!
i have the followng code and its not setting the correct values to the variable:

$var1 = rand(1, 3);
$var2 = rand(1, 4);

this doesnt save the renaodm numbers, but it does create the variabl i know i havent reassinge the variable contence anywhere, so ts stayed the same i know this becauase i go if (empty($var1)) {echo "var1 is EMPTY!!!!!";} and the same with var 2

so is this the right way to asigne random numbers, becauase its worked in other parts of the site.

Random Number Exemple Between 1 And 100
I was wondering how could i get a random number exemple between 1 and
100 but with n% of getting some value over a number x.

Random 6 Digit Number
how do i get a random 6 digit number in php guys?

Random Number And Words
can you think of a smaller way to get a random number with words.

<?php

$words=range(a,z);

$num=range(1,9);

$x=array_merge($words,$num);

shuffle($x);

for($i=0; $i<7; $i++){

echo $x[(rand(0,6))];
} ?>

Loop And Random Number
I am trying to create a script that will output a featured merchant from mysql database. Here is what I have:

   $result = mysql_query("SELECT max( id ) as id FROM `merchants`");

   $row = mysql_fetch_array( $result );
     
   $max = $row[id];

   srand ((double) microtime( )*1000000);

   $random_number = rand(2,$max);

   $merchantid = mysql_query("SELECT * from merchants where $random_number=id");

   $row = mysql_fetch_array( $merchantid );

   for ( $featured=$random_number; $featured <> $row[id]; $random_number = rand (2,$max))
      {
      }

   echo $row['merchant'];

Sometimes it works quickly and sometimes takes quite awhile. I am very new to this, so am not sure the correct way. I didn't want the maximum value to exceed the highest value I already have in the database (I thought this might make it quicker). I also need the script to loop because I have several merchants that have been deleted through the years and not all id are consecutive.

Reproducible Random Number Series
I need to generate reproducible random number series.

I've done the obvious - use mt_srand with the same seed. This supposedly
will create the same series every time.

Is this true? Its not working for me.

By the way, seeding mt_srand with different integers doesn't necessarily
produce different series. I've done a little testing and every pair of
consecutive even and odd numbers produces the same series. eg. seed 0 and 1
produce the same series, as does 10000 and 10001.

Change Filenames According To Random Number
Well, this script get today's date, tomorrow's date, generates a random number, count all jpg files in a directory and prints all jpg filenames. Here is the code:

Random Number Excluding Specified Value In Array
the most efficient way to generate a random number
from a range that will not return values specified in an array?

Checking If Its A 6 Digit Random Number
$password = "274826";

how can i check if $password is a 6 digit number

Check Input Field Not Random Letters
I want a script that will check if the value of a text field is an actual word or if it is just random digits eg gdfgawgwre is there a way of doing this? i have looked at pspell but i don't care if the words spelt correctly just as long as it isn't random letters/numbers.

Temp Table - Random Number Generator
I am developing a data entry program where information is entered into a form, then submitted to a databse.

I need to be able to set up a temporary table which houses this data and then when all transactions are complete, the data in the temporary table is entered into my permanent table - then the temp table is deleted. (I won't get into the details as to why this has to be done this way)

Setting up the table is simple, however I ran into a bit of a wall when it comes to having several people entering data at the same time. If they were all to use the same temp table, then when one user finishes (and the table is auto-dropped) then other users data entry would be killed.

SOLUTION:
Use a random generator to name the temp tables, that way I can have several data entry users without running the risk of losing data when the temp tables are dropped.

PROBLEM
I don't know the best method to make a random number generator

Can anyone help, or suggest a simple, yet effective generator?

Generating Random Number Without The Generated Numbers Already ??
i make a function that return random numbers but it will not generate another random number if he already pass the value  for example it  return 2, so after i call the function random again it will not return another 2 i want another numbers to be returned instead ?

function random($max){
srand ((double) microtime( )*1000000);
$random_number = rand(0,$max);
return $random_number;}

Multi-file Upload And Random Four Digit Number Filename?
when trying to modify my single file upload that includes renaming the file uploaded to include a random four digit number at the begining. This is my code for the single file upload: Code:

Check If Number Is In An Array
how can i check if a specified number is in an array e.g

number =5
searching in array (1,2,3,4,5)

I know how to do it for a mysql query, but I need to do it in PHP, anyone kno how i could do this. Also say I have several numbers I want to check are in the array, how would I do this.

Check If Number Is A Mulitple Of 3
I'm sure this is very easy, my brain is useless at arithmetic I just need to find if a number is a multiple of 3. Just trying to add a by 2 get one free deal so if they've got 3 or 6 etc then i give one free.

How Can I Check If A Number Is Round Or Not ?
How can i check if a number is round or not ?

Check Number Off Emails On Server?
in my admin, I want to make an overview of details about my CMS. On of the details is the number of new emails on my server. Can I do this with PHP?

Check If A Number Is Decimal Or Normal ?
How can i check if a number is decimal or normal ?

Update If Unique User And Unique Id?
I have a site which lists some links on a page.Each link gets parsed to "/out.php?entryid=x" When they do this, my out.php updates the number of times that has been viewed It then pushes them on to the appropriate link.

To prevent "gaming" of the link count, I want to try and use the IP or a session or something that will mean users can not inflate the count of any one link by more than 1. Code:

Check Week Number In End Of Year And Begiining Of New Year?
I am creating a little own calendar. Now I want to add a "previous week" and "next week" functionality to the calendar.

It is easy to take $thisWeek - 1; and $thisWeek + 1;, but there has to be a check wether it is the last week of the year and it should actually be a new year and head to week number 1. HOW do I make this kind of function? I use the following string names:

$thisYear
$thisWeek

Replace Hex Number Or Decimal Number In A String ?
String may contain alphanumeric values. What is the bestway to replace a hex number such as 0x122aaa and decimal number such as 5678 with a string "blah" Example: I want to replace below--

wr_thru1 data or mask mismatch!! for addr=0x00000b73a0540 & mdfid:11
with
wr_thru1 data or mask mismatch!! for addr=hexVal & mdfid:decVal

Order Number Or Tracking Number
I need to create some kind of random number within a persons session that can be inserted into a customer id column for their orders, customer, and credit card tables.

Unless their is a better way to link a customers information together between a few tables besides using auto increment. Things could get screwed up for me if I use auto increment, especially if someone submits their information but does not actually place an order.

My question is " How can I create a random order number that can be used within a persons session and will stay the same throughout the whole program for that one person? "

Unique ID
I remember seeing something about this somewhere but can't seem to find it now.

I have a form results page I want to display to users, and I only want them to only see there particular info.

This is no problem like this results.php?uid=1

but what's to stop them from typing in other numbers and viewing other peoples info.

How do I get random unique ID's and can I use this as my auto_incremented, primary key? or is that a contradiction.

Unique URL
Is there a way to acheive in php an unique url, like myspace does, without actually creating a folder? For example, "myspace.com/name"?

Unique Id
i want to make each table name i made by php automaticlly :

for example when i get username, password, ... from user,  instead of storing the in a table ROW, i create a TABLE for each user, so for this, i need uniqe table names , like  user1, user2 , user 3 .

can make the table names auto_increment ?
i did once by php , i counted the rows of database results, and added 1 to the count result, then made that a table name , but my problem is , when i delete a table from database, so the rows that was counted become 1 less. so the next table name will be the same as the last .

Unique Value In Field
I'm trying to do a query of PHP on MySQL, basically searching a field, varchar field it is...and basically I only want it to return the first occurence of a value..

Say:

ID Text
1 Hello
2 Hi
3 Hello
4

I only want it to return ID 1 not 3, is this possible??


Copyright © 2005-08 www.BigResource.com, All rights reserved