----- Original Message -----
From: "Bas Jobsen" <[EMAIL PROTECTED]>
To: "Sheridan Saint-Michel" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
Sent: Thursday, October 04, 2001 7:17 PM
Subject: Re: [PHP-DB] Howto make a double LEFT JOIN


> Hello Sheridan Saint-Michel,
>
> Well it works fine, tnx!!!
>
> But now i want to understand it too.....
>
> bit_count(bit_or(1<<table1.sid)) ??

okay... 1<<table1.sid is leftshift the number 1 table1.sid times.
Your result will be a binary number... which will be the number 1 followed
by table1.sid 0's.  Once you have this you do a bitwise or of all the
numbers you have shifted.  This means any two rows where sid was the same
will be combined, as there is no difference between (1 or 1) and (1 or 0).
The last step, then, is to count the 1 bits and see how many different sid's
there were.

Make Sense?  The problem before was that there was no way to differentiate
one row from another, and thus no way to combine identical rows  =P

> What does bit mean? I thougt "1<<table1.sid" was something like a backward
> bit(e)swich stepsize 1??
>
> I creat my sid by:
> srand((double)microtime()*1000000);
> $sid = md5(uniqid(rand()));
>
> a the sid-field as varchar(32) (i realise now, maybe better use char(32))
> (Maybe you will ask why i don't use a auto_increment sid (int(9) or
> something like that). Cause I don't want the table will be full ever
> (sid>999.999.999))

ACK!  Don't do this.  You do know that an unsigned int (using a signed int
in an auto_increment field is pointless anyway) has a max value of
4294967295, right?  To put this into perspective... if you had one million
customers, they would have more than 4294 transactions EACH before sid
filled up.  If you are still worried about running out of numbers in your
sid field make it an unsigned bigint.  The max value for an unsigned bigint
is 18446744073709551615... so that should give you lots of space to play in,
and sid will only be 8 bytes per row... not 33 (Also incidentally, if you do
want to save an md5 value to a row in the future... use char not varchar as
you know it will be 32 bytes and are adding a wasted 33rd byte).

(If you need more than 18 Quintillion transactions, which comes out to
around 3 billion transactions for EVERY PERSON ON EARTH, please let me know
what kind of business you are in... as I am obviously in the wrong one  =P )

> Now i thougth bit_count(bit_or(32<<table1.sid)) should do the trick, but
it
> doesn't?

See my explanation above.  All you are trying to do is shift a 1 digit to a
different place for each unique value of sid.  The above definately won't
work if sid is an md5 value as md5 includes a-z characters.

> Best regards,
>
> Bas

 Again, hope that helps  =)

Sheridan Saint-Michel
Website Administrator
FoxJet, an ITW Company
www.foxjet.com


-- 
PHP Database 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]

Reply via email to