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
https://forums.phpfreaks.com/topic/216553-how-to-check-against-bitwise-saved-data/
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.

 

 

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.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.