How can I unserialize a value from MySQL and assign the values in a
variable using PHP/CodeIgniter?
Hello guys I just need a little help here about unserializing MySQL
values. What I want is after getting the serialized value from my database
I will assign the unserialized value in a variables.
Here's my code
//THIS IS THE QUERY
$sqlGetSerializedValues = "SELECT cscart_order_data.order_id AS order_id,
cscart_order_data.data as data_serialize FROM cscart_orders
LEFT JOIN cscart_order_data
ON cscart_orders.order_id =
cscart_order_data.order_id
WHERE type = 'I'";
$resultGetSerialize = $this->db->query($sqlGetSerializedValues);
$var_data = array();
foreach($resultGetSerialize->result_array() as $row1){
$var_data[] = $row1['data_serialize'];
}
unserialize($var_data); //How can i get the selected value
print_r($var_data);
OUTPUT:
Array
(
[0] => a:2:{s:6:"points";i:100;s:4:"cost";i:100;}
[1] => a:2:{s:6:"points";i:100;s:4:"cost";i:100;}
[2] => a:2:{s:6:"points";i:294;s:4:"cost";i:294;}
[3] => a:2:{s:6:"points";d:107;s:4:"cost";d:107;}
[4] => a:2:{s:6:"points";i:163;s:4:"cost";i:163;}
[5] => a:2:{s:6:"points";i:322;s:4:"cost";i:322;}
[6] => a:2:{s:6:"points";i:289;s:4:"cost";i:289;}
[7] => a:2:{s:6:"points";i:9;s:4:"cost";i:9;}
[8] => a:2:{s:6:"points";i:500;s:4:"cost";i:500;}
[9] => a:2:{s:6:"points";i:500;s:4:"cost";i:500;}
[10] => a:2:{s:6:"points";i:301;s:4:"cost";i:301;}
[11] => a:2:{s:6:"points";i:500;s:4:"cost";i:500;}
[12] => a:2:{s:6:"points";i:490;s:4:"cost";i:490;}
[13] => a:2:{s:6:"points";i:103;s:4:"cost";i:103;}
For example I want to get the "points" and assign in a variable $points.
How can i do that? An also the cost. Ok that's all Thanks in advance.
No comments:
Post a Comment