Please see table below:
items
id title fields
1 Dog [{"id":"11","value":"50"},{"id":"19","value":"100"},{"id":"22","value":"150"}]
2 Cat [{"id":"19","value":"50"},{"id":"22","value":"100"},{"id":"37","value":"150"}]
3 Bird [{"id":"14","value":"50"},{"id":"19","value":"100"},{"id":"22","value":"150"}]
4 Mouse [{"id":"16","value":"50"},{"id":"22","value":"100"},{"id":"34","value":"150"}]
5 Horse [{"id":"6","value":"50"},{"id":"22","value":"100"},{"id":"47","value":"150"}]
I want to echo the sum of all the values that equals to id 22 I am a complete novice to php and mysql and will appreciate any assistance, so please explain the code to me clearly.
This is what I have found, but does not work:
<?php
if ($fields->id == 22) {
$result += $fields['value'];
}
return $result;
?>
please help.... thank you
var_dump($fields);Also i guess you need to loop throught he items and find the sum.