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

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

  1. ceg

    ceg Member

    Joined:
    2 Aug 2011
    Messages:
    26
    Likes Received:
    5
    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:
    640
    Likes Received:
    500
    Reputations:
    72
    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...
Similar Threads - Правильный запрос FrameWork
  1. dorosh88
    Replies:
    7
    Views:
    1,163
  2. Alt_er
    Replies:
    1
    Views:
    4,600
  3. Zmii666
    Replies:
    2
    Views:
    3,618
  4. kanai
    Replies:
    4
    Views:
    3,219