Правильный запрос в БД. FrameWork Codeigniter

Discussion in 'PHP' started by ceg, 27 Feb 2021.

  1. ceg

    ceg New Member

    Joined:
    2 Aug 2011
    Messages:
    22
    Likes Received:
    3
    Reputations:
    0
    У меня выводится сумма значений одного столбца из базы данных. Как вывести сумму не всех значений, а только за последние 30 дней? Столбец с датой называется, например, date.

    PHP:
    public function get_data_logs(){
    ...
    $total_spent_receive  0;
    ...
    $total_spent_receive    $this->get_sum_value($this->tb_transaction_logs"`status` = 1");
    ...
    }
    $data = (object)array(
     ...
     
    "total_spent_receive"   => $total_spent_receive,
     ...
    );
    PHP:
    public function index(){
           
    $data = array(
               
    "module"         => get_class($this),
               
    "data_log"       => $this->model->get_data_logs(),
           );
    }
    Вывод:
    PHP:
    <?php
    $data_orders_log  
    $data_log->data_orders;
    (!empty(
    $data_log->total_spent_receive))
    ?>
     
  2. lifescore

    lifescore Elder - Старейшина

    Joined:
    27 Aug 2011
    Messages:
    631
    Likes Received:
    494
    Reputations:
    69
    Code:
    SELECT
        SUM(total_spent_receive)
    FROM
        tb_transaction_logs
    WHERE
        `timestamp` >= SUBDATE(CURRENT_TIMESTAMP(), INTERVAL 30 DAY) AND `status` = 1;
     
    web456web likes this.
Loading...