Welcome Guest, Not a member yet? Register   Sign In
Help for add values
#1
Sad 

Hello,

I need help to help me correct my php function in codeigniter. I have a database; I want addi all values of " from_user_id ".

I use this sql to get the desired result.

Code:
SELECT SUM(kiff_envoi+kiff_recu+visite_recu+profile_visite+da_recu+da_envoi+topic_poster+repon_topic+conv_envoi+conv_recu) AS total_stats FROM score WHERE from_user_id = ?



I use this function. It allows me to check if " from_user_id " exists, if it exists, we calculate the total different tables and we update the result in " total_stats ". If " from_user_id " does not exist, create it. But my function does not return me the right result.

I had to make a big mistake but I do not know where! Does someone could help me please. print_r($result); return 0 in database !

PHP Code:
public function count_tout_stats($user_id//total des stats 

{
$this->db->select('(kiff_envoi+kiff_recu+visite_recu+profile_visite+da_recu+da_envoi+topic_poster+repon_topic+conv_envoi+conv_recu) as total_stats');
$this->db->from('score'); 
$this->db->where('from_user_id'$user_id);

$result $this->db->get()->row_array();
print_r($result);

if (
$this->ttl_stats_score($user_id) > 0// Check si exists dans 'score' 
{
 
   $data = array( 
 
       'total_stats' => $total_stats
    
);
 
   $this->db->where('from_user_id'$user_id);
 
   $this->db->update('score'$data);
}
else
{
 
   $data = array( 
 
       'from_user_id' => $user_id,
 
       'total_stats' => $total_stats
    
);
 
   $this->db->insert('score'$data);  
}

return 
$total_stats;


public function 
ttl_stats_score($user_id)
{
$this->db->where('from_user_id'$user_id);
$this->db->from('score');

return 
$this->db->count_all_results();  

Reply
#2

(This post was last modified: 12-11-2015, 03:53 AM by Violette.)

Thank you very much LaPouleLustucru
it works perfectly.
You were me of great help!
kiss
Reply




Theme © iAndrew 2016 - Forum software by © MyBB