I am trying to fetch the number of rows for a query using a Moodle function.
This is what I have done so far:
$records = $DB->get_records_sql("select * from {user} where maildigest=$login_id");
How do I get the number of results?
I am trying to fetch the number of rows for a query using a Moodle function.
This is what I have done so far:
$records = $DB->get_records_sql("select * from {user} where maildigest=$login_id");
How do I get the number of results?
You can use a Moodle specific function to count records:
$DB->count_records($table);
In your case you can use:
echo $DB->count_records('user', array('maildigest'=>$login_id));
This function has been designed to improve efficiency: you do not need to retrieve a whole bunch of data if you just want to count the retrieved records;-)
get_records_sql() retruns an array, so use count()
to get number of records.
Do like below:-
$records=$DB->get_records_sql("select * from {user} where maildigest=$login_id");
echo (count($records));
Link section you have to refer:- https://prnt.sc/gpggq4