我需要帮助在codeigniter

时间:2015-12-10 05:04:31

标签: codeigniter

我需要帮助来帮助我在codeigniter中更正我的php功能。 我有一个数据库;我想要addirionner所有的" from_user_id"。

Check data

我使用这个sql来获得所需的结果。

 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 = ?

在codeingniter中我使用这个功能。 它允许我检查是否" from_user_id"存在,如果它存在,我们计算总不同的表,我们更新结果在" total_stats"。如果" from_user_id"不存在,创造它。 但是我的功能并没有给我正确的结果。

我不得不犯一个大错,但我不知道在哪里! 有人可以帮助我吗。

public function count_tout_stats($user_id) //total des stats 

{
$this->db->select_sum(conv_recu, conv_envoi, repon_topic, etc...);
$query = $this->db->from('score'); 
$this->db->where('from_user_id', $user_id);

$total_stats = $this->db->count_all_results();

if ($this->ttl_stats_score($user_id) > 0) // Check if exists  
{
    $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(); 
}

提前感谢您的帮助

紫罗兰

1 个答案:

答案 0 :(得分:0)

你可以试试这个:

$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);

您将获得结果