Go Back   SitePoint Forums > Forum Index > Program Your Site > PHP
Newsletter FAQ Members List Calendar Mark Forums Read

New to SitePoint Forums? Register here for free!

SitePoint Sponsor
 
Reply
 
Thread Tools Display Modes
Old May 18, 2006, 18:52   #1
Ken Iovino
SitePoint Addict
 
Ken Iovino's Avatar
 
Join Date: Oct 2003
Location: Florida
Posts: 287
bitfields tutorial

vBulletin uses what they call bitfields in there system. Basicly you can have multiple settings within one database field. Is there any tutorial out there to show how one can do such a thing to custom scripts?

I always notice..
PHP Code:

$var = array(

        
'can_do_this'  => 1,
        
'can_do_that'  => 2,
        
'can_try_this' => 4,
        
'can_do_those' => 8
);
But never fully understode whats going on. Whats this called and can you point me to any tutorials avaiable? Thanks!
Ken Iovino is offline   Reply With Quote
Old May 18, 2006, 19:13   #2
chris_fuel
SitePoint Wizard
 
chris_fuel's Avatar
 
Join Date: May 2006
Location: Ventura, CA
Posts: 2,837
Ok, this explanation should do it:

http://www.zend.com/zend/spotlight/c...lery-wade2.php

basically, you take an integer with a certain bit length, and you flag on/off certain bits to indicate permissions/etc. This is done through the various php bitwise operators:

http://us3.php.net/manual/en/languag...rs.bitwise.php

This is mainly done to save storage space. Though some people find it hard to work with on the database level, as they have to reference back and forth between the db and PHP code, which, for a DB admin who doesn't deal with PHP much, that can be quite painful . That said, if you're the one dealing with both the DB and the code, it's all you. However, if you have a DB admin, be considerate .
chris_fuel is offline   Reply With Quote
Old May 18, 2006, 19:17   #3
Ken Iovino
SitePoint Addict
 
Ken Iovino's Avatar
 
Join Date: Oct 2003
Location: Florida
Posts: 287
I deal with everything, so this should do well for me. Thanks alot Chris!

/me starts to read away!

Edit:


This cartoon really helped alot. I want to post it here for other users.

source: http://www.litfuel.net/tutorials/bitwise.htm
Ken Iovino is offline   Reply With Quote
Old May 18, 2006, 20:58   #4
chris_fuel
SitePoint Wizard
 
chris_fuel's Avatar
 
Join Date: May 2006
Location: Ventura, CA
Posts: 2,837
hahaha, what.. on.. earth... I am so bookmarking that, that's the greatest . Oh and btw, spiral is awesome ( at least I think that's where that character is from.. ).
chris_fuel is offline   Reply With Quote
Old May 19, 2006, 04:58   #5
Ken Iovino
SitePoint Addict
 
Ken Iovino's Avatar
 
Join Date: Oct 2003
Location: Florida
Posts: 287
I thought you might get a kick out of that.
Ken Iovino is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread | Next Thread »

Thread Tools
Display Modes

 
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Sponsored Links
 
Forum Jump


All times are GMT -7. The time now is 00:58.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Copyright 1998-2009, SitePoint Pty Ltd. All Rights Reserved