Transdimensional Bitfields - Generate Bit Sets within a Bit Set
by
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: PHP Code:
$items=$vbulletin->db->query_write("SELECT FROM " . TABLE_PREFIX . "Items name,type,owner");
In the template itembits we have the following code: Code:
<div>$item[name] || $item[type] || $item[owner]</div> 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: PHP Code:
$owner=$item['owner'];
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: PHP Code:
$items=$vbulletin->db->query_write("SELECT FROM " . TABLE_PREFIX . "Items name,type,owner");
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) |