Как получить сумму столбца таблицы базы данных в CodeIgniter [дубликат]Php

Кемеровские программисты php общаются здесь
Ответить
Anonymous
 Как получить сумму столбца таблицы базы данных в CodeIgniter [дубликат]

Сообщение Anonymous »

Я не могу получить сумму открытых позиций. Я получаю 1 (один) вместо общей суммы. Помогите мне решить эту проблему.
Контроллер:
function index()
{
$userId = $this->phpsession->get("userId");
$userType = $this->phpsession->get('userType');
$date = date("Y-m-d");
if (!$userId && !$this->phpsession->get("userType")) {
redirect(base_url() . 'user');
}

$config['base_url'] = base_url() . 'requirement/index';
$config['total_rows'] = $this->requirement_model->GetRequirement(array("count" => true));
$config['per_page'] = 5;
$config['cur_tag_open'] = '';
$config['cur_tag_close'] = '';

$this->pagination->initialize($config);

$options['offset'] = $this->uri->segment(3);
$options['limit'] = $config['per_page'];
$options['join'] = true;

$data['clients'] = $this->client_model->ajaxclient();
$data['requirements'] = array("" => "Choose requirement");

$data['requirement'] = $this->requirement_model->GetRequirement($options);
$data['links'] = $this->pagination->create_links();
$data['totalactive'] = $this->requirement_model->GetRequirement(array("find" => true));
$data['totalrequirement'] = $this->requirement_model->GetRequirement(array("totalreq" => true));
$data['openpositions'] = $this->requirement_model->GetRequirement(array("openpos" => true));
//print_R($data['openpositions']);exit;
//echo "
"; print_R($this->db->last_query()); exit;

$data['page_title'] = "Requirement Details";
$this->layout->view("requirement/index", $data);
}

Модель:
function GetRequirement($options = array())
{
if (isset($options['requirementId']))
$this->db->where('requirementId',$options['requirementId']);

if (isset($options['clientName']))
$this->db->where('clientName', $options['clientName']);

if (isset($options['limit']) && isset($options['offset']))
$this->db->limit($options['limit'], $options['offset']);
elseif (isset($options['limit']))
$this->db->limit($options['limit']);

$this->db->order_by("activateddate", "DESC");

if (isset($options['join'])) {

$this->db->select('r.*,c.clientName as cName');
$this->db->from('requirement as r');
$this->db->join('clients as c','c.clientId=r.clientName');
$query = $this->db->get();
if (@$options['requirementId'])
return $query->row(0);
return $query->result();
}

if (isset($options['find'])) {
$this->db->select('distinct(clientName)');
$this->db->from('requirement');
$this->db->where('(clientName) and (noofpositions > 0) ');
$this->db->count_all();
$query = $this->db->get();
return $query->num_rows();
}

if (isset($options['totalreq'])) {
$this->db->select('requirementName');
$this->db->from('requirement');
$this->db->where('(noofpositions > 0) ');
$this->db->count_all();
$query = $this->db->get();
return $query->num_rows();
}

if (isset($options['openpos'])) {
$this->db->select_sum('openPos');
$this->db->from('requirement');
$this->db->where('(closedPos = 0) ');
$this->db->count_all();
$query = $this->db->get();
return $query->num_rows();
}

$query = $this->db->get('requirement');

if (isset($options['count']))
return $query->num_rows();

if (@$options['requirementId'])
return $query->row(0);

return $query->result();
}

Просмотр:


Total Positions Opened



Подробнее здесь: https://stackoverflow.com/questions/259 ... odeigniter
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Php»