Answer the question
In order to leave comments, you need to log in
How to properly sample?
Let's say we need to form an array for subsequent output to the site statistics table:
$data = [
// ...
'sms' => [
'new' => [
'today' => ORM::factory('Sms')
->where('created', '>', mktime(0, 0, 0, date('m'), date('d'), date('Y')))
->and_where('status_id', '=', ORM::factory('Sms_Status')
->where('name', '=', 'new')->find()
)
->count_all(),
'yesterday' => ORM::factory('Sms')
->where('created', '<', mktime(0, 0, 0, date('m'), date('d'), date('Y')))
->and_where('created', '>', mktime(0, 0, 0, date('m', time() - Date::DAY), date('d', time() - Date::DAY), date('Y', time() - Date::DAY)))
->and_where('status_id', '=', ORM::factory('Sms_Status')
->where('name', '=', 'new')->find()
)
->count_all(),
'hour' => ORM::factory('Sms')
->where('created', '>', time() - Date::HOUR)
->and_where('status_id', '=', ORM::factory('Sms_Status')
->where('name', '=', 'new')->find()
)
->count_all(),
'day' => ORM::factory('Sms')
->where('created', '>', time() - Date::DAY)
->and_where('status_id', '=', ORM::factory('Sms_Status')
->where('name', '=', 'new')->find()
)
->count_all(),
// ...
'all' => ORM::factory('Sms')
->and_where('status_id', '=', ORM::factory('Sms_Status')
->where('name', '=', 'new')->find()
)
->count_all(),
],
'sent' => [
// ...
'all' => ORM::factory('Sms')
->and_where('status_id', '=', ORM::factory('Sms_Status')
->where('name', '=', 'sent')->find()
)
->count_all(),
],
'not_sent' => [
//...
'all' => ORM::factory('Sms')
->and_where('status_id', '=', ORM::factory('Sms_Status')
->where('name', '=', 'not_sent')->find()
)
->count_all(),
],
],
// ...
];
->and_where('status_id', '=', ORM::factory('Sms_Status')
->where('name', '=', 'not_sent')->find()
Answer the question
In order to leave comments, you need to log in
select st.name, count(0) from Sms join Sms_status st on status_id = st.id where st.name in ('sent','not_sent', 'new') group by status_id
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question