I currently have a bits system set up with my web app, which is used to set awards. Heres an example function: // ###################### Add bits ####################### \\ /** * Returns int of selected bits * * @param array Array of selected bits * @return int */ function bits_add($arr) { if (!is_array($arr)) return pow(2, $arr-1); $bits = 0; foreach ($arr as $value) $bits += pow(2, $value-1); return $bits; } PHP: Now, I didn't develop this so I'm a bit shaky on bits in general, but I know it is used to lighten the load on the database. Unfortunately, bits also limit me in that I cannot change them or delete them without causing some serious synchronization issues. What would be an alternative for this? I'm assuming a new table in the database? Thanks in advance.
what, does this store some settings/values as binary data in an int? If that's what it does, you are only saving storage space with the server. Anyway, explain a bit more what the script does, and I'll try to help. As far as a new table, it might be desireable, but all you need will probably be a few new columns on the current table.
i did something similar before. its a bit hard to explain, but i try it. lets say you have a website selling real estate and you want to show if a house/flat/whatever has some extras like pool, ocean view, garage, garden, whirlpool etc. each extra can be true (it has this extra) or false (no extra). now you can start to insert 10-50 true/false fields in your database for each extra and update the code and database every time someone comes up with a new extra, which you dont want. the better solution is to use a single int-field "extras" in your database and encode all this extras to a number: leta say a house has pool(1), NO ocean view(2), NO garage(4), garden(8): extras=1+8=9 so you insert a 9 into your "extras" field. you need another table or array to assign this extras to numbers(1,2,4,8,16 etc.) of course. hope you get the idea behind this code
Yeah, great example falcondriver, it basically is a method of saving space when storing data, but it does limit flexibility. I am just looking for a "best practice" way to instead store the data in a more flexible but possibly less space-saving or query-saving way.
hm i dont know what webserver you have, but i would do it in php - assume its faster than start another one or 2 db-querys. if you have mssql or some "better" database you should write a function for the database and just call them via script - this should be the fastes way afaik.
Unfortunately I am using MySQL, how else would I do it in php? I was thinking maybe seperate the awards by commas (instead of bits): 1, 2, 3 and then use php to implode it?