L
L
lexstile2021-11-09 19:00:33
SQL
lexstile, 2021-11-09 19:00:33

How to properly organize the receipt of a list of data with an additional field - quantity?

There is a request like this:

public function getAll($data) {
    $params = [
      'user_id' => $data->user_id,
      'period' => $data->period,
      'limit' => $data->limit,
      'offset' => $data->offset,
    ];

    return $this->db->row('SELECT id, amount, DATE_FORMAT(date, "%d.%m.%Y %H:%i:%s") as date FROM enrollments WHERE user_id = :user_id && status = 1 && UNIX_TIMESTAMP(date) > :period ORDER BY id DESC LIMIT :limit OFFSET :offset', $params);
  }

I would like this query to return the amount of data in total - without offset and limit , but put them separately from the array of elements, is it possible to do this somehow?
I really don't want to make a separate second query to count elements.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2021-11-09
@lexstile

And what prevents after receiving all the elements to simply take the size of the resulting array?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question