bugcoder Posted October 22, 2010 Share Posted October 22, 2010 hi all, I have an array(1,2,3,4) and i make a form and make checkboxes for this array and user selects 2,3 and 4 when user submit form then i save it in table by making selected check boxes and converting selected values into bitwise equivalent value like this foreach($data['meal_types'] as $v){ $mealTypeBits += pow(2,$v-1); } Now when i have to show user his selected data how will i compare table bitwise saved record with array(1,2,3,4) to get the values that he checked while saving. Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted October 22, 2010 Share Posted October 22, 2010 We'll have to wait for a math wiz. Since you know the allowable choices this may be able to be done. I would use this instead maybe: // to save it $mealTypeBits = serialize($data['meal_types']); // then when you retrieve it $mealTypeBits = unserialize($rowFromDB['column_name']); But if you need it to be indexable or searchable then you should use separate columns for each choice. Quote Link to comment Share on other sites More sharing options...
bugcoder Posted October 22, 2010 Author Share Posted October 22, 2010 might be i was not able to make you understand what i want in this case. Serialize is the option for me but here i have to save by converting array values to bitwise. so here i am using bitwise converstion of all user selected ids to save in field instead of serializing method. im able to save data in bitwise but what im not able to know yet is that i want method to compare array(1,2,3,4) to saved record field and to get which array values are saved in bitwise formate in record. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.