Your problem is here: $my_graph =
. At every iteration you are resetting the entire string to a new value. You need $my_graph .=
— notice the .
— to concatenate a string together. That is a PHP syntax problem.
I don’t think I would do it this way though. update_usermeta()
will serialize an array or object if it needs to so this…
update_usermeta( $user_id, 'my_great_graph', $ga->getResults() );
… would store your raw data for use later. Or…
foreach($ga->getResults() as $result) {
$my_graph[] = array(
'Visiteurs' => $result->getVisitors(),
'Visites' => $result->getVisits(),
'number' => (-$i++),
);
}
update_usermeta( $user_id, 'my_great_graph', $my_graph );
… should store the processed data in such a way that it can be used in multiple ways later. A processed string is difficult to use for anything but an echo
.
get_user_meta($user_id, 'my_great_graph')
would automatically un-serialize the data for you.