In a Mysql Database the value of a field is like this:
a:1:{i:0;s:1:"3";}
The value i need here is the 3.
If it is a normal number i could sum up selected field with the query but like this i fail
Is it possible to make the math within the query or do i have to process the result of the query (how?) ?
Update due to Answer of @kabirbaidhya Making the unserialize here Online gives the right result.
Processing the Query gives not the expected
function summe_bilden()
{
global $wpdb;
$value = $wpdb->get_results("SELECT VALUE FROM wp_vxcf_leads JOIN wp_vxcf_leads_detail ON wp_vxcf_leads.id = wp_vxcf_leads_detail.lead_id WHERE name = 'stunden'");
foreach($value as $a)
{
$arr = unserialize($a);
var_dump($a);
echo $arr[0];
}
}
object(stdClass)#9463 (1) { ["VALUE"]=> string(18) "a:1:{i:0;s:1:"3";}" } object(stdClass)#9464 (1) { ["VALUE"]=> string(20) "a:1:{i:0;s:3:"9,5";}" } object(stdClass)#9465 (1) { ["VALUE"]=> string(20) "a:1:{i:0;s:3:"7,5";}" }
Update 2: Final working code for me:
foreach($value as $a)
{
$array = $a->VALUE;
$ar = unserialize($array);
echo $ar[0];
echo '</br>';
}