I need some help designing this last feature of my PHP/MySQL forum RPG system. I have been working on this for weeks (learning both languages at once) and need help designing a condition monitor (the one seen here [url]http://shadowrunrpg.com/resources/sheets/SR3_character_sheet.pdf[/url] because this is Shadowrun based). I wanted to do a system of checkboxes and then they will retain their checked value with the “checked” attribute of the checkbox. I’m just not sure how to store the data so that it can be echoed later or so when people view other peoples profiles they see their current stats. I was told to try to use bitfields but I’m not usre how to and I did do searches. Thanks for any help.
@phpnoviceFeb 20.2005 — #I would only mess with "bitfields" if you're concerned about storage. Otherwise, I would use standard Boolean data types. Then, your checkboxes could be quite simply output as follows: [code=php] <input type=checkbox" ... <?=($rst['stat1'])?'checked':''?>> <input type=checkbox" ... <?=($rst['stat2'])?'checked':''?>> <input type=checkbox" ... <?=($rst['stat3'])?'checked':''?>> [/code]
[B]I would only mess with "bitfields" if you're concerned about storage. Otherwise, I would use standard Boolean data types. Then, your checkboxes could be quite simply output as follows:
@phpnoviceFeb 20.2005 — #[i]Originally posted by Max Headroom [/i]
[B]What do you mean for the "..."?[/B][/QUOTE] Other normal HTML attributes for INPUT. [i]Originally posted by Max Headroom [/i]
[B]Also, does this mean that I need to create twenty new fields for the different stats?[/B][/QUOTE] Yes, that is what I would do.
Your other choice is to encode them into a single long integer field. You can do this with up to 31 true/false options. You can use [B]bindec()[/B] and [B]decbin()[/B] to convert back and forth.
@phpnoviceFeb 21.2005 — #Speaking of which... Anybody know a better way to convert a long integer to a bit array than the following method? [code=php]<?php $bitarray = explode(":", wordwrap( strrev( str_pad( decbin($decval), 31, "0", STR_PAD_LEFT)), 1, ":", 1)); ?>[/code]