Register Members List Search Today's Posts Mark Forums Read

Article Options
Transdimensional Bitfields - Generate Bit Sets within a Bit Set
Join Date: Mar 2005
Posts: 393

by Attilitus Attilitus is offline 08 Aug 2007

This is a fairly simple concept, but it really allows you to do alot more dynamic template work while staying firmly rooted within vBulletin's template system.

First lets talk about the basic use of Bitfields. Lets imagine that you have a list of 20 items. These items have the following 3 identifiable features:

Item Name
|| Item Type || Item Owner

Now lets say that you have 20 of these items stored in your database each with a value to go under one of the three aforementioned fields. Surely you would not want to manually enter in all 20 items directly into the database. Instead you would need to use bitfields:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

The above script queries the database to retrieve all results within table Items and then goes through each row one by one and evaluates the individual row as an array within the template.

In the template itembits we have the following code:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

And we can display all of these bits that were processed in the php script (all 20 of them displayed in the format setup in the template itembits) by adding the following variable into our templates: $itembits.

Now all this is fine and dandy and pretty basic.

But you run into a small problem if there is the potential to have an infinite number of owners stored in an array each with its own specific details. Lets imagine that we want to display all the owners of the item and each of those owner's personal details in the same list. However, we do not know how many owners there are.

Lets pretend that $item['owner'] is stored in the database as a serialized multi-dimensional array and contains the identities and personal details of 200 owners (10 for each of the 20 $items).

The array is structured like this:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

There is an $owner[0] through $owner[19] for every item (20 in all). But remember we do not actually know how many there will be as new owners can be added at any time.

If we were to try to edit the template "itembits" to contain all the information of the owners we would have quite a job on our hands, and would be writing messy templates. Perhaps the best solution is to simply avoid this kind of issue all together but for those of you who want a way around it here is the solution:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Is this example rather ridiculous? Is the solution rather simple? Is this solution (especially in this example) an inefficient solution to the problem?

The answer is probably "Yes" for all of the above.

However, I have come across certain specific situations that have required this kind of implementation, and I figured I would share a solution that has aided me a couple of times.

Next Article: Transdimensional Bitfields Within Transdimensional Bitfields
(Using a new object instance for each bitfield call... and two database queries...!!!!!!!111!1!!eleven)
Views: 1791
Reply With Quote
Old 09 Aug 2007, 15:32
Princeton's Avatar
Princeton Princeton is offline
Join Date: Nov 2001
Real name: Joe Velez
thank you for sharing
Former Staff Member

Latest Articles:
Liquid Layout = Less Ad Revenue?
How to Monetize Your Site
Improve Web Page Performance
How To Write For The Web

If it needs instructions, there's room for improvement.
Give users what they actually want, not what they say they want. And whatever you do, don't give them new features just because your competitors have them!
Reply With Quote

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Article Options

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

New To Site? Need Help?

All times are GMT. The time now is 03:00.

Layout Options | Width: Wide Color: