/    Sign up×
Community /Pin to ProfileBookmark

Checkbox field…

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.

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@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]
Copy linkTweet thisAlerts:
@Max_HeadroomauthorFeb 20.2005 — [i]Originally posted by phpnovice [/i]

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

[code=php]
<input type=checkbox" ... <?=($rst['stat1'])?'checked':''?>>
<input type=checkbox" ... <?=($rst['stat2'])?'checked':''?>>
<input type=checkbox" ... <?=($rst['stat3'])?'checked':''?>>
[/code]
[/B][/QUOTE]


What do you mean for the "..."? Also, does this mean that I need to create twenty new fields for the different stats?
Copy linkTweet thisAlerts:
@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.
Copy linkTweet thisAlerts:
@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]
×

Success!

Help @Max_Headroom spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...