Hi

First of all you can use the Bitwise Operators to set/clear a bit
Let say $a is '00100' meaning group 2 is set and you want to set group 4 then 
write: $a = $a | (pow(2 ,4)); //using OR Operator
Now $a is '10100'
Let say that you want to unset group 2:
$a = $a ^ (pow(2,2)); //using XOR Operator


In Mysql:
Let say you want to select groups 2,4,5
In your select string you should write something like :

$mygroups = (pow(2,2) + pow (2,4) + pow(2,5));
$sql = 'select * from sometable where groups = ' || $mygroups


Hope I was helpful
Yaron Khazai


-----Original Message-----
From: news [mailto:[EMAIL PROTECTED] On Behalf Of Robert S
Sent: Tuesday, March 29, 2005 12:35 PM
To: php-general@lists.php.net
Subject: [PHP] php + mysql: binary arrays

I am writing a contact manager in php/mysql.  I'd like to use a binary array
as an efficient way to store information for groups that each contact
belongs to eg:

Field: 'group': 001010 means that the contact belongs to the second and
fourth group.

If the array is of type Byte, it should be able to store information about
255 groups.

Is php/mysql able to handle this?  My specific questions are:

What functions set/clear a bit in an array in php?
How do you query whether a bit is set in mysql?

I hope I've made this clear enough to be followed - I'm not a pro!

-- 
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

Reply via email to