[PHP] Unique ID on 5.0.4 (Windows)

2005-09-21 Thread Chris

Hi,

Pretty soon I'm going to be needing to generate a unique identifier in a 
script. I'm looking into how to go about doing it now.


It has to work on Apache 2 / PHP 5.0.4 (Module) / Windows 2000 Server.

Any suggestions on how I might be able to do it?

I've noticed the uuid PECL package, which looks like it could work for 
me, but I'm not sure it will work on Windows, or where to get it if it did.


I have access to Visual Studio 6, so I think I could compile it if I had 
to. Anyone have experience compiling PECL extensions on Windows?


I'd appreciate any help you could give me.

Thanks,
Chris

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Unique ID on 5.0.4 (Windows)

2005-09-21 Thread Dragan Stanojevic - Nevidljivi

Hi Chris,

Chris wrote:
Pretty soon I'm going to be needing to generate a unique identifier in a 
script. I'm looking into how to go about doing it now.


It has to work on Apache 2 / PHP 5.0.4 (Module) / Windows 2000 Server.

Any suggestions on how I might be able to do it?

I'd appreciate any help you could give me.


What you need is called hash function (function for creating keys in 
hash tables). In PHP manual they are categorized under String functions...


The way they work is that for any given string they return a (index) 
number (it can be shown a string of hex numbers) which is unique or 
almost unique (depending on the algorithm).


The ones you may be interested are: md5, sha1, crc32

http://www.php.net/md5
http://www.php.net/sha1
http://www.php.net/crc32

Failing those, you may use mhash functions:
http://www.php.net/manual/en/ref.mhash.php

Hope this will help you a little,
N::


smime.p7s
Description: S/MIME Cryptographic Signature


Re: [PHP] Unique ID on 5.0.4 (Windows)

2005-09-21 Thread Chris

Dragan Stanojevic - Nevidljivi wrote:


Hi Chris,

Chris wrote:

Pretty soon I'm going to be needing to generate a unique identifier 
in a script. I'm looking into how to go about doing it now.


It has to work on Apache 2 / PHP 5.0.4 (Module) / Windows 2000 Server.

Any suggestions on how I might be able to do it?

I'd appreciate any help you could give me.



What you need is called hash function (function for creating keys in 
hash tables). In PHP manual they are categorized under String 
functions...


The way they work is that for any given string they return a (index) 
number (it can be shown a string of hex numbers) which is unique or 
almost unique (depending on the algorithm).


The ones you may be interested are: md5, sha1, crc32

http://www.php.net/md5
http://www.php.net/sha1
http://www.php.net/crc32

Failing those, you may use mhash functions:
http://www.php.net/manual/en/ref.mhash.php

Hope this will help you a little,
N::


I think you may have misunderstood me, sorry. I need to generate a 
unique string, to use as an identifier, in a script, not something to 
identify the script itself. A hash won't work for that.


Thanks anyway though.
Chris

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Unique ID system - need help/ideas

2004-03-10 Thread J J
I was given a database that has uniques IDs such as:

AL1
AL2
AR1
AR2
MI1
etc...

The first two letters are based on the state they live
in, then it would need to look at the next 5
characters to determine the next ID.  

My problem is how do I recreate this in PHP to make
sure any newly added records follow this same unique
ID? 


So if I insert another Alabama record the id would be:
AL3

Or insert a record from a new state would be:
NY1 (so NY0 is the default starting point)



Any ideas? Thank you in advance!


__
Do you Yahoo!?
Yahoo! Search - Find what you’re looking for faster
http://search.yahoo.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Unique ID system - need help/ideas

2004-03-10 Thread Chris W. Parker
J J mailto:[EMAIL PROTECTED]
on Wednesday, March 10, 2004 3:46 PM said:

 Any ideas? Thank you in advance!

does it all have to be in the same field? can you not just combine two
fields?

one field would be called 'id' and it would be auto-incrementing.
second field would be 'state' and it would contain the two letter
abbreviation.

i can think of a few other ways to get it all into one field, but
they're a bit less efficient. then again i'm no sql expert.



chris.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Unique ID system - need help/ideas

2004-03-10 Thread J J
I'd like to keep it in one field if possible since
that's how their database is now and data will be
going back and forth.

Plus there should be allowed two of the same numbers,
so like:

AL3
KY3

So any state with more than one record can be
sequential and not jump around like KY3, AL4,
KY5, etc.  

Make sense?

--- Chris W. Parker [EMAIL PROTECTED] wrote:
 J J mailto:[EMAIL PROTECTED]
 on Wednesday, March 10, 2004 3:46 PM said:
 
  Any ideas? Thank you in advance!
 
 does it all have to be in the same field? can you
 not just combine two
 fields?
 
 one field would be called 'id' and it would be
 auto-incrementing.
 second field would be 'state' and it would contain
 the two letter
 abbreviation.
 
 i can think of a few other ways to get it all into
 one field, but
 they're a bit less efficient. then again i'm no sql
 expert.
 
 
 
 chris.
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 


__
Do you Yahoo!?
Yahoo! Search - Find what you’re looking for faster
http://search.yahoo.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Unique ID system - need help/ideas

2004-03-10 Thread Chris W. Parker
J J mailto:[EMAIL PROTECTED]
on Wednesday, March 10, 2004 4:03 PM said:

 I'd like to keep it in one field if possible since
 that's how their database is now and data will be
 going back and forth.

[snip]

 So any state with more than one record can be
 sequential and not jump around like KY3, AL4,
 KY5, etc.
 
 Make sense?

yeah that makes sense. hmm.. well i'll give you my idea.. but it's very
possible there's a better way to do it (than what i'm going to suggest).

ok. one field will be used. it'll be a text (varchar) field. before you
do an insert you'll need to find out what's in there ahead of time and
then adjust accordingly. i'd select the last record that contained the
two letter abbreviation, find out what the number was, increment it,
then reconstruct the id and insert the new one.

this of course won't prevent the exact same process from happening at
the exact same time. i mean, two sessions could pull the same id and
then reconstruct the (new, but) same id.

make sense?


chris.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Unique ID system - need help/ideas

2004-03-10 Thread J J
Will it be able to figure out what the last number is
if it's a character type and the number is something
like 3?  So it'll add one to make it 4 and not
something like 10003.

??


--- Chris W. Parker [EMAIL PROTECTED] wrote:

 yeah that makes sense. hmm.. well i'll give you my
 idea.. but it's very
 possible there's a better way to do it (than what
 i'm going to suggest).
 
 ok. one field will be used. it'll be a text
 (varchar) field. before you
 do an insert you'll need to find out what's in there
 ahead of time and
 then adjust accordingly. i'd select the last record
 that contained the
 two letter abbreviation, find out what the number
 was, increment it,
 then reconstruct the id and insert the new one.
 
 this of course won't prevent the exact same process
 from happening at
 the exact same time. i mean, two sessions could pull
 the same id and
 then reconstruct the (new, but) same id.
 
 make sense?
 
 
 chris.
 

__
Do you Yahoo!?
Yahoo! Search - Find what you’re looking for faster
http://search.yahoo.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Unique ID system - need help/ideas

2004-03-10 Thread Chris W. Parker
J J mailto:[EMAIL PROTECTED]
on Wednesday, March 10, 2004 4:22 PM said:

 Will it be able to figure out what the last number is
 if it's a character type and the number is something
 like 3?  So it'll add one to make it 4 and not
 something like 10003.

php knows. you'll just have to pad the string with zeros.

?php

  $number = 01;

  ++$number;

  echo $number;

?

that will output 2 not 101.


chris.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Unique ID system - need help/ideas

2004-03-10 Thread Miles Thompson
At 04:10 PM 3/10/2004 -0800, Chris W. Parker wrote:
J J mailto:[EMAIL PROTECTED]
on Wednesday, March 10, 2004 4:03 PM said:
 I'd like to keep it in one field if possible since
 that's how their database is now and data will be
 going back and forth.
[snip]

 So any state with more than one record can be
 sequential and not jump around like KY3, AL4,
 KY5, etc.

 Make sense?
yeah that makes sense. hmm.. well i'll give you my idea.. but it's very
possible there's a better way to do it (than what i'm going to suggest).
ok. one field will be used. it'll be a text (varchar) field. before you
do an insert you'll need to find out what's in there ahead of time and
then adjust accordingly. i'd select the last record that contained the
two letter abbreviation, find out what the number was, increment it,
then reconstruct the id and insert the new one.
this of course won't prevent the exact same process from happening at
the exact same time. i mean, two sessions could pull the same id and
then reconstruct the (new, but) same id.
make sense?

chris.
Yes Chris, that's the right idea. The problem is that this is being done 
across the 'Net. Ideally you try and get a lock on the row for a given 
state, fetch the value and increment/update, then release the lock. In a 
web environment locks are a little tricky - what happens if a connection is 
lost or times out?

For the original poster:  Having said all this, make certain that there is 
a unique, system-generated, primary key for each table. As these keys 
*never* have to be seen by the public, don't get tampered with, etc., they 
can be safely relied on for inter-table relationships. Down the road they 
will save your bacon.

If the purpose of having separate numbering sequences for each state is to 
keep track of a count, why bother? Just select for a count on each state. 
If it's a matter of ego, in that if I have a lower registration number I 
have higher status, well fill your boots with whatever scheme will work.

Really look at this v. closely. Quite often clients insist on wacko 
numbering schemes which they are convinced are important, but frequently 
result only because that's the way it's always been done. Also remember 
there should be no data encoding within a field - that's why so many 
columns are possible.

Example, membership numbers like MABT082003BM2, where the first four 
characters are my initials, the next six the date I joined,  and each of 
the next the colour of my eyes, marital status and number of children, ARE 
FORBIDDEN. All that information belongs in separate fields. This is what 
you are tending towards with AL0003 and KY00107. Bad practice.

As I'm Canadian, if I stepped on any toes I'll apologize in advance. g

Cheers - Miles

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


RE: [PHP] Unique ID system - need help/ideas

2004-03-10 Thread J J
Yeah thanks for the feedback, I'm already including a
primary key auto_increment field in place to tie the
tables together with an ID I *know* will be unique. 
This other ID scheme is just to work within their
existing system that uses this.  I'm just trying to
mirror/maintain that scheme for their purpose.


--- Miles Thompson [EMAIL PROTECTED]
wrote:
 
 
 For the original poster:  Having said all this, make
 certain that there is 
 a unique, system-generated, primary key for each
 table. As these keys 
 *never* have to be seen by the public, don't get
 tampered with, etc., they 
 can be safely relied on for inter-table
 relationships. Down the road they 
 will save your bacon.
 
 If the purpose of having separate numbering
 sequences for each state is to 
 keep track of a count, why bother? Just select for a
 count on each state. 
 If it's a matter of ego, in that if I have a lower
 registration number I 
 have higher status, well fill your boots with
 whatever scheme will work.
 
 Really look at this v. closely. Quite often clients
 insist on wacko 
 numbering schemes which they are convinced are
 important, but frequently 
 result only because that's the way it's always been
 done. Also remember 
 there should be no data encoding within a field -
 that's why so many 
 columns are possible.
 
 Example, membership numbers like MABT082003BM2,
 where the first four 
 characters are my initials, the next six the date I
 joined,  and each of 
 the next the colour of my eyes, marital status and
 number of children, ARE 
 FORBIDDEN. All that information belongs in separate
 fields. This is what 
 you are tending towards with AL0003 and KY00107. Bad
 practice.
 
 As I'm Canadian, if I stepped on any toes I'll
 apologize in advance. g
 
 Cheers - Miles
 
 -- 

__
Do you Yahoo!?
Yahoo! Search - Find what you’re looking for faster
http://search.yahoo.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Unique ID system - need help/ideas

2004-03-10 Thread trlists
On 10 Mar 2004 J J wrote:

 My problem is how do I recreate this in PHP to make
 sure any newly added records follow this same unique
 ID? 

I haven't played much with these functions but I think for MySQL you'd 
want something like this, for the state XX (excuse the wrapped 
lines):

if ($result =
mysql_query(select max(id) from table where left(id, 2) = 'XX')) {
$row = mysql_fetch_row($result);
$newid = strpad($row[0] + 1, 5, 0, STR_PAD_LEFT);
mysql_query(insert into table set id = 'XX' . $newid);
$newrecnum = mysql_insert_id();
}

That is crude and uuntested, needs some error checking and most likely 
table locking, but it's one possibility for a base.

--
Tom

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Unique ID system - need help/ideas

2004-03-10 Thread J J
Wow I think you are on to something!!! I'll give it a
whirl!

Thanks!


--- [EMAIL PROTECTED] wrote:
 On 10 Mar 2004 J J wrote:
 
  My problem is how do I recreate this in PHP to
 make
  sure any newly added records follow this same
 unique
  ID? 
 
 I haven't played much with these functions but I
 think for MySQL you'd 
 want something like this, for the state XX (excuse
 the wrapped 
 lines):
 
   if ($result =
   mysql_query(select max(id) from table where
 left(id, 2) = 'XX')) {
   $row = mysql_fetch_row($result);
   $newid = strpad($row[0] + 1, 5, 0,
 STR_PAD_LEFT);
   mysql_query(insert into table set id = 'XX' .
 $newid);
   $newrecnum = mysql_insert_id();
   }
 
 That is crude and uuntested, needs some error
 checking and most likely 
 table locking, but it's one possibility for a base.
 
 --
 Tom
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 


__
Do you Yahoo!?
Yahoo! Search - Find what you’re looking for faster
http://search.yahoo.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Unique ID - again

2004-02-12 Thread Alex
Hi folks,
I'm using usual md5(microtime()); to create IDs, but now I've encountered a
problem with that. I need to create explicitly 6 digit unique
number(decimal). Yes, I know I can use for/while loop to fill a string with
digits, but is it ABSOLUTELY sure that the random will never return same
number when seed is microtime()? It is very important as the number will
identify a bank transfer...

Is there any other way than checking with all previous IDs? Or some MySQL
function to do this for me?

thank you
Alex

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Unique ID - again

2004-02-12 Thread Richard Davey
Hello Alex,

Thursday, February 12, 2004, 11:00:41 AM, you wrote:

A I'm using usual md5(microtime()); to create IDs, but now I've encountered a
A problem with that. I need to create explicitly 6 digit unique
A number(decimal). Yes, I know I can use for/while loop to fill a string with
A digits, but is it ABSOLUTELY sure that the random will never return same
A number when seed is microtime()? It is very important as the number will
A identify a bank transfer...

If the data is so important - why are you restricting it to a 6 digit
key? You should ideally use the uniqid() function perhaps with a
combined lcg entropy at the end. That will give you a 13 character
long unique id - or md5 it for a 32 character one (see the manual for
examples).

A Is there any other way than checking with all previous IDs? Or some MySQL
A function to do this for me?

For something so important I would use (a) a longer unique ID and (b)
I'd still run a SQL check to see if the ID has been already used or
not. A simple MySQL count will bring that result back very quickly.

-- 
Best regards,
 Richardmailto:[EMAIL PROTECTED]

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Unique ID - again

2004-02-12 Thread Galen
MySQL (or another SQL database) is the answer. You can check for an 
existing OR use it's auto_increment or whatever else you like.

Create a field to track all this stuff. There is no other way to 
guarantee that an ID is unique than to check it against existing. 
Random functions yield random results, so each time, there is ALWAYS 
a chance of a number being repeated. Microtime works pretty well, but 
there is STILL a chance two people could have a transaction at the same 
time. Yes, the odds can be insanely, insanely small for various 
functions (i.e. MD5) but as you shorten the length of your number, the 
odds get higher.

And yes, it's important to realize that a 6 digit unique identifier is 
limited to 1 million possible combinations, not nearly enough for most 
banks.

I might suggest you do some more PHP learning before you go and develop 
an online bank application - this stuff is pretty fundamental 
programming and database concepts. If your overall skill level isn't 
very high, you're likely to make mistakes, and either have errors, 
problems in functionality, or, worse, security problems.

-Galen

On Feb 12, 2004, at 3:00 AM, Alex wrote:

Hi folks,
I'm using usual md5(microtime()); to create IDs, but now I've 
encountered a
problem with that. I need to create explicitly 6 digit unique
number(decimal). Yes, I know I can use for/while loop to fill a string 
with
digits, but is it ABSOLUTELY sure that the random will never return 
same
number when seed is microtime()? It is very important as the number 
will
identify a bank transfer...

Is there any other way than checking with all previous IDs? Or some 
MySQL
function to do this for me?

thank you
Alex
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Unique ID

2003-11-12 Thread Marek Kilimajer
Javier Muniz wrote:
Neither auto-increment nor sequences allow you to do what you're asking for
though, which is like database garbage collection.  If you really need
something like this you should implement it in a cron job that runs during
non-peak hours as it will be quite an expensive operation on a large table
(the best way I can think of would be to iterate over all table rows and
look for gaps in the table, and for each gap take the record with the
highest ID and change the ID to fill the gap, then update all replys to
match the new ID, after everything is finished reset the sequence to the
highest id in the modified table and you're done).
I would not care about removing old posts. Good archive is always good :)

I don't know what you mean that your database could get huge, in my 
understanding that means millions of post per week.

Note from the MySQL manual for you auto_increment fans out there:

Posted by Jim Martin on Tuesday October 1 2002, @11:57am  

Just in case there's any question, the
AUTO_INCREMENT field /DOES NOT WRAP/. Once you
hit the limit for the field size, INSERTs generate
an error. (As per Jeremy Cole)
That is I will be able to insert only 4294967295 rows if the 
auto_increment is UNSIGNED INT. :( I guess I'll start to use UNSIGNED 
BIGINT, that will give me 18446744073709551615 rows, that ought to be 
enough for anybody. ;)

Marek

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Unique ID

2003-11-11 Thread Dimitri Marshall
Hi there,
Here's my situation:

I'm making a message board and I've decided the best way to go about the
structure is to have 3 tables, two of them will be Posts and Replys.
Now, in order for this ti work, each post has to have a UniqueID - same with
the replys. Looking at another program, I can see that one way to do this is
to do it by rows (ie. count how many rows, add 1, then that is the ID). It
would be unique because no two rows would be 1 for example.

The problem I can see is that the database would become incredibly huge
(size wise I mean). I want to delete the posts after 30 days, and if I
delete the row, then that would mess up the row system.

Any suggestions?

Dimitri Marshall

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Unique ID

2003-11-11 Thread Marek Kilimajer
Dimitri Marshall wrote:
Hi there,
Here's my situation:
I'm making a message board and I've decided the best way to go about the
structure is to have 3 tables, two of them will be Posts and Replys.
Now, in order for this ti work, each post has to have a UniqueID - same with
the replys. Looking at another program, I can see that one way to do this is
to do it by rows (ie. count how many rows, add 1, then that is the ID). It
would be unique because no two rows would be 1 for example.
The problem I can see is that the database would become incredibly huge
(size wise I mean). I want to delete the posts after 30 days, and if I
delete the row, then that would mess up the row system.
Any suggestions?
Have you heard about auto_increment? Read on:
http://www.mysql.com/doc/en/example-AUTO_INCREMENT.html
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


RE: [PHP] Unique ID

2003-11-11 Thread Javier Muniz
auto_increment is not in the SQL standard, and not everyone uses MySQL.  To
be cross-compatible between databases use a Sequence:
http://pear.php.net/manual/en/package.database.db.intro-sequences.php
provides a brief introduction, the PEAR::DB class allows you to use
sequences easily.

Neither auto-increment nor sequences allow you to do what you're asking for
though, which is like database garbage collection.  If you really need
something like this you should implement it in a cron job that runs during
non-peak hours as it will be quite an expensive operation on a large table
(the best way I can think of would be to iterate over all table rows and
look for gaps in the table, and for each gap take the record with the
highest ID and change the ID to fill the gap, then update all replys to
match the new ID, after everything is finished reset the sequence to the
highest id in the modified table and you're done).  

Note from the MySQL manual for you auto_increment fans out there:

Posted by Jim Martin on Tuesday October 1 2002, @11:57am  

Just in case there's any question, the
AUTO_INCREMENT field /DOES NOT WRAP/. Once you
hit the limit for the field size, INSERTs generate
an error. (As per Jeremy Cole)

And the comment a few beyond that regarding being able to drop the index and
renumber doesn't help here, as there is an exterior resource (the reply
table) that will be broken as soon as the ids change.

If anyone has a better suggestion on how to do this I'd love to hear it :) 

-Javier

 -Original Message-
 From: Marek Kilimajer [mailto:[EMAIL PROTECTED] 
 Sent: Tuesday, November 11, 2003 3:30 PM
 To: Dimitri Marshall
 Cc: [EMAIL PROTECTED]
 Subject: Re: [PHP] Unique ID
 
 
 Dimitri Marshall wrote:
  Hi there,
  Here's my situation:
  
  I'm making a message board and I've decided the best way to 
 go about 
  the structure is to have 3 tables, two of them will be Posts and 
  Replys. Now, in order for this ti work, each post has to have a 
  UniqueID - same with the replys. Looking at another 
 program, I can see 
  that one way to do this is to do it by rows (ie. count how 
 many rows, 
  add 1, then that is the ID). It would be unique because no two rows 
  would be 1 for example.
  
  The problem I can see is that the database would become incredibly 
  huge (size wise I mean). I want to delete the posts after 
 30 days, and 
  if I delete the row, then that would mess up the row system.
  
  Any suggestions?
 
 Have you heard about auto_increment? Read on: 
 http://www.mysql.com/doc/en/example- AUTO_INCREMENT.html
 
 -- 
 
 PHP General Mailing List 
 (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Unique ID

2003-11-11 Thread Boyan Nedkov
Dimitri Marshall wrote:
Hi there,
Here's my situation:
I'm making a message board and I've decided the best way to go about the
structure is to have 3 tables, two of them will be Posts and Replys.
Now, in order for this ti work, each post has to have a UniqueID - same with
the replys. Looking at another program, I can see that one way to do this is
to do it by rows (ie. count how many rows, add 1, then that is the ID). It
would be unique because no two rows would be 1 for example.
The problem I can see is that the database would become incredibly huge
(size wise I mean). I want to delete the posts after 30 days, and if I
delete the row, then that would mess up the row system.
Any suggestions?

Dimitri Marshall

A standard solution in this case is to use one common table for all messages, 
both 'posts' and 'replays', distinguishing them by 'type' (TypeID, say 1 for 
post, 2 for replay), and then build a parent/child relationship between both 
type of messages in that table. In this way each message will have unique id. 
When you need all or some 'post' messages, use a query for selecting TypeID = 1, 
resp. TypeID = 2 for 'replay' messages.

Concerning the deletion of a message (post or replay), you should write a query 
which will recursively delete the message selected as well as all child messages 
assigned to that (parent) message. The easiest way to do this is to use 
triggers, but that depends on the database you work with.

To get closer to this approach and to find some nice examples, check out the 
following resources:

http://www.sqlmag.com/Articles/Index.cfm?ArticleID=8826
http://www.sqlteam.com/item.asp?ItemID=8866
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/acdata/ac_8_qd_14_5yk3.asp
http://www.yafla.com/papers/sqlhierarchies/sqlhierarchies.htm
HTH,

Boyan
--
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Unique ID

2003-11-11 Thread John W. Holmes
Marek Kilimajer wrote:
Dimitri Marshall wrote:
I'm making a message board and I've decided the best way to go about the
structure is to have 3 tables, two of them will be Posts and Replys.
Now, in order for this ti work, each post has to have a UniqueID - 
same with
the replys. Looking at another program, I can see that one way to do 
this is
to do it by rows (ie. count how many rows, add 1, then that is the 
ID). It
would be unique because no two rows would be 1 for example.

The problem I can see is that the database would become incredibly huge
(size wise I mean). I want to delete the posts after 30 days, and if I
delete the row, then that would mess up the row system.
Any suggestions?
Have you heard about auto_increment? Read on:
http://www.mysql.com/doc/en/example-AUTO_INCREMENT.html
Keep reading about database design, too. You'll only need one table and 
a parent-child relationship. The initial post will have a parent of 
zero and child posts under it will have a parent column relating 
back to the original post.

I may not have explained that the best way, but there are plenty of 
articles out there about it. Have fun. :)

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals  www.phparch.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] unique id

2003-07-28 Thread Gabriel Guzman
On Sat, 2003-07-26 at 07:11, Curt Zirzow wrote:
 * Thus wrote jan ([EMAIL PROTECTED]):
  Hi there!
  
  What's the best way to create uids (unique ids) even when runnig at
  exactly same time (microseconds)?
  
  is this enough ???
  
  $r = mt_rand();
  $uid = uniqid(getmypid() . $r);
 
 If you're running a cluster of machines I would include information
 on the machine that is generating the uid.
 
 $uid = uniqid(getmypid() . $r . '_MACHINE_NAME_');
 
 Curt

this is similar to what we do as well: 

hexadecimal timestamp + hexadecimal pid + hexadecimal randomvalue + hex
ip address of server (only used if using multiple machines, otherwise
this part is left off).  

I've also considered using semaphores in my id generation function to
insure only one counter can be created at a time, but am worried that
this might cause a bit of a performance hit.  Anyone tried this? 

gabe. 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] unique id

2003-07-28 Thread Curt Zirzow
* Thus wrote Gabriel Guzman ([EMAIL PROTECTED]):
 On Sat, 2003-07-26 at 07:11, Curt Zirzow wrote:
  * Thus wrote jan ([EMAIL PROTECTED]):
   Hi there!
   
   What's the best way to create uids (unique ids) even when runnig at
   exactly same time (microseconds)?
   
   is this enough ???
   
   $r = mt_rand();
   $uid = uniqid(getmypid() . $r);
  
  If you're running a cluster of machines I would include information
  on the machine that is generating the uid.
  
  $uid = uniqid(getmypid() . $r . '_MACHINE_NAME_');
  
  Curt
 
 this is similar to what we do as well: 
 
 hexadecimal timestamp + hexadecimal pid + hexadecimal randomvalue + hex
 ip address of server (only used if using multiple machines, otherwise
 this part is left off).  
 
 I've also considered using semaphores in my id generation function to
 insure only one counter can be created at a time, but am worried that
 this might cause a bit of a performance hit.  Anyone tried this? 

The only other way I have done it was to make a central database
with a table containing a auto incremented id. All scripts
would add a record and get back the auto incremented id number.
Since db inserts are atomic, it is guaranteed to be unique.

I think the biggest weak point in this approach is if the
connection goes down between the web server and db server, the
script is left clueless as what to do.


Curt
-- 
I used to think I was indecisive, but now I'm not so sure.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] unique id

2003-07-26 Thread jan
Hi there!

What's the best way to create uids (unique ids) even when runnig at
exactly same time (microseconds)?

is this enough ???

$r = mt_rand();
$uid = uniqid(getmypid() . $r);

thanks

Jan



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] unique id

2003-07-26 Thread Tom Rogers
Hi,

Saturday, July 26, 2003, 5:58:41 PM, you wrote:
j Hi there!

j What's the best way to create uids (unique ids) even when runnig at
j exactly same time (microseconds)?

j is this enough ???

j $r = mt_rand();
j $uid = uniqid(getmypid() . $r);

j thanks

j Jan


I use:

$id = md5(uniqid(rand(),1));

-- 
regards,
Tom


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] unique id

2003-07-26 Thread Curt Zirzow
* Thus wrote jan ([EMAIL PROTECTED]):
 Hi there!
 
 What's the best way to create uids (unique ids) even when runnig at
 exactly same time (microseconds)?
 
 is this enough ???
 
 $r = mt_rand();
 $uid = uniqid(getmypid() . $r);

If you're running a cluster of machines I would include information
on the machine that is generating the uid.

$uid = uniqid(getmypid() . $r . '_MACHINE_NAME_');

Curt
-- 
I used to think I was indecisive, but now I'm not so sure.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] unique id

2002-10-29 Thread Edward Peloke
How do I generate a uniqueid in php?  

Thanks,
Eddie


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] unique id

2002-10-29 Thread 1LT John W. Holmes
 How do I generate a uniqueid in php?  

www.php.net/uniqid

---John Holmes...

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] unique id

2001-01-10 Thread Richard Lynch

*WHY* not use auto_increment?

Would the builtin http://php.net/uniqid function not work better?

*NEVER* seed the random number generator more than once per script.  Call
srand() once, and only once.

The return() statement will return the MySQL resource ID, which is probably
not useful, but all the other variables will be forgotten so I think
whatever pointer and loop position 0 you mean will be reset-- assuming all
this is in a function.

You are limiting yourself to 9 - 1 records, which is pretty small.

Basically, you almost for sure are making your life difficult and should
just use auto_increment.

- Original Message -
From: AJDIN BRANDIC [EMAIL PROTECTED]
Newsgroups: php.general
Sent: Tuesday, January 09, 2001 11:14 AM
Subject: [PHP] unique id


 Hi again,

 I am generating a randum number but before inserting it into a table I
 want to make sure that onother number with the same value doesn't exist
 in the table. Here is what I have:

 srand((double)microtime()*100);
 $ran_num = rand(1, 9);

 $query01 = "SELECT thisnum FROM mytable";
 $results = mysql_query($query01) or die("Failed on select
 mytable!");

   while ($result = mysql_fetch_array($results)) {
 $thisnum=$result['thisnum'];
 if($ran_num==$thisnum) {
   srand((double)microtime()*100);
   $ran_num = rand(1, 9);
   reset($results)
  // will this reset the pointer and will the
 while loop start from position 0??? If not how do I force the check to
 start from position 0?
 }
   }

 I donot want to use autoincrement???

 Thanks

 Ajdin

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]