Jump to content

how to check against bitwise saved data?


bugcoder

Recommended Posts

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.

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.