// Add new income for the day
function add_new_income($user_id, $budget_group_id, $day, $month, $year, $income)
{
// Check if there has been posted anything at the same day
$this->db->where('day', $this->current_date);
$this->db->where('month', $this->current_month);
$this->db->where('user_id', $user_id);
$this->db->where('budget_group_id', $budget_group_id);
$query = $this->db->get('budget_day', 1);
// Check if something was found
if ($query->num_rows() > 0) {
// If something was found, update the value
$data = array('income_total' => $income);
$this->db->update('budget_day', $data);
}
}
Поможет ли это? Или мне нужно запустить новый оператор «db->where()»?
Мне интересно, нужно ли мне дважды выбирать (операторwhere), если я хочу обновить конкретного пользователя в базе данных. Пример: [code]// Add new income for the day function add_new_income($user_id, $budget_group_id, $day, $month, $year, $income) { // Check if there has been posted anything at the same day $this->db->where('day', $this->current_date); $this->db->where('month', $this->current_month); $this->db->where('user_id', $user_id); $this->db->where('budget_group_id', $budget_group_id);
$query = $this->db->get('budget_day', 1);
// Check if something was found if ($query->num_rows() > 0) { // If something was found, update the value $data = array('income_total' => $income); $this->db->update('budget_day', $data); } } [/code] Поможет ли это? Или мне нужно запустить новый оператор «db->where()»?