homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

Determining combination of powers of 2

 5:50 am on Dec 18, 2009 (gmt 0)

Hey all.

I've been stuck with a particularly tricksy problem. The developer that previously worked on the project I am busy with developed a news module with articles and categories. Each news article can be assigned to one or more news categories.

However, the manner in which these news categories have been referenced is perplexing. The system uses bitwise operations to calculate "new" category IDs (For example, news article with category ID 256 actually belongs to category with ID 8).

The real problem comes in when a news article belongs to multiple categories. The shifted values of the two (or more) genres to which the news article belongs are added together, and then stored as a single integer value in the database. My problem comes in when I'm needing to break this single integer value apart into the constituent category IDs, so that I can query the names of the categories to which it belongs.

If anybody could offer some help, or provide some sort of starting help, I'd seriously appreciate it. My brain is feeling absolutely frazzled - I've been having to deal with logs, which I haven't done since high school! :)



 11:11 am on Dec 19, 2009 (gmt 0)

Can you query the data using the bit functions [dev.mysql.com]?


 1:11 am on Dec 21, 2009 (gmt 0)

I've wanted to get into this same powers of 2 system for user permissions, but didn't really get anywhere with it when I last looked into.


It would still be a great way to go if I could crack it.


 1:17 am on Dec 21, 2009 (gmt 0)



Haven't got time to test it right now, but it looks right.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved