This topic is locked

random charectors

5/19/2008 12:18:31 AM
PHPRunner General questions
G
gizmoman author

I write software using Delphi and cannot get my head around PHP so hopefully someone can help.
One of my programs uses MYSQL as a databse and when it adds records, it genorates a string of 100 charectors, randomly and I use this to idedentify that record (Key Field)
Can I do the same using PHP runner so that when I add a record using the ADD page, it will genorate 100 charecters and place that in the field?
I saw some other posts re simalar and think it will but need a bit of a hand.
Peter

A
alang 5/19/2008

I generally use the "autoincrement" in MySQL for generating a unique key field - it's pretty straightforward and requires no special PHP. What is the advantage in getting 100 random characters? Wouldn't it be less efficient once you got a few records in there - particularly if you have it included in other tables as a foreign key?

G
gizmoman author 5/20/2008

The database runs on several machines inclusing ones in my car and they are not all connected together. I use the field to identify records during sync. The auto increment can cause the same number to appear on several databases but in different records

I generally use the "autoincrement" in MySQL for generating a unique key field - it's pretty straightforward and requires no special PHP. What is the advantage in getting 100 random characters? Wouldn't it be less efficient once you got a few records in there - particularly if you have it included in other tables as a foreign key?

S
steveh 5/21/2008

Random characters can clash as well.
Why not just add a source field and use that and the autoincrement field together, source would be "car" or whatever.

G
gizmoman author 5/21/2008

Thanks for the suugestions but no one has simply answered the original question.
Can I get PHPRunner to create 100 charectors and add to a field as it creates a record? And if so, can someone help me achieve it? Why I need the field doesn't matter. Its there and its staying. I simply would like to get a web interface and I can use phprunner and like it but need the above

Random characters can clash as well.

Why not just add a source field and use that and the autoincrement field together, source would be "car" or whatever.

J
Jane 5/22/2008

Hi,
to generate random number and save it in the field use Before record added event.

Use rand() PHP function in it:

http://php.net/manual/en/function.rand.php

G
gizmoman author 5/22/2008

Thanks heaps.
So can I convert that to what in Delphi or Pascal is called a STRING (letters) and add them to each other to make up 100 charecters
Like
Var

Randomkey : String;

Begin

While Length(randomkey) < 100 do

Randomkey :=Randomkey + FloatToStr(Random);
End;
In other words, how is this done in PHP

Hi,

to generate random number and save it in the field use Before record added event.

Use rand() PHP function in it:

http://php.net/manual/en/function.rand.php

J
Jane 5/23/2008

Hi,
it's PHPRunner-related forum.
To convert your custom code to PHP check PHP manual:

http://php.net/manual/en/function.rand.php

http://php.net/manual/en/function.strlen.php