Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Outputting bit efficiently

Database Field Output

Outputting bit efficiently

by  webmigit  Posted    (Edited  )
Unless you're programming for your own website where you know what the value means, when you display the value of a bit (yes/no) database field on a page you probably run something like this..

Code:
<cfif query.bitparam eq 0>
Not allowed
<cfelse>
Allowed
</cfif>

Which is typically what I do too but I have an output of about 400 rows in one site which has 4 bit values for each row.. meaning 1600 cfifs...

I don't like that...

So what I do when I have cases like that is..

Code:
<cfset ArrBool=ArrayNew(1)>
<cfset ArrBool[1]="Not Allowed">
<cfset ArrBool[2]="Allowed">

before any cfloops or cfoutputs

And then in my output of the bit field I say..

Code:
#ArrBool[bitfieldname+1]#

If the value is 0, it will read dimension one because of the + 1, if the value is 1, it will read dimension two because of the +1.

Plus I can use that on all four bits outputted four hundred times so I'm saving a lot of cfifs.

I haven't ran a timer on the page to find out.. haven't studied it in depth but I know two things.. It appears much faster to me and everyone else looking at the page on any computer and it makes adding another bit field and outputting even easier than the common cfif/cfelse.

Enjoy!
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top