get_records_sql returns only one result on Assignment grading page

get_records_sql returns only one result on Assignment grading page

von ramesh verma -
Anzahl Antworten: 2

I am trying to display all assignment result to teacher in moodle and using below query.

When i am using following query:

if (!$this->is_downloading()) {

            $this->rawdata = $DB->get_records_sql($sql, $this->sql->params, $this->get_page_start(), $this->get_page_size());

           

        } else {

            $this->rawdata = $DB->get_records_sql($sql, $this->sql->params);

        }


I get only single record but when i use same query directly in my SQL then i get all of all records.


So please let me know how to get all records when i use this query in moodle.

Also how to display all assignment result to teacher in moodle 

Als Antwort auf ramesh verma

Re: get_records_sql returns only one result on Assignment grading page

von Cristian Matos -

Hi,

This is a common mistake with this function.  get_records_sql will create an array with the first column of your query as index for each element, so try to include the primary key as the first column in your select.

Example:  SELECT id, course, name, intro...

A bad example would be: SELECT course, name, intro

Hope this help.

Als Antwort auf Cristian Matos

Re: get_records_sql returns only one result on Assignment grading page

von Tim Hunt -
Nutzerbild von Core developers Nutzerbild von Documentation writers Nutzerbild von Particularly helpful Moodlers Nutzerbild von Peer reviewers Nutzerbild von Plugin developers

Note that, if you have Debugging set to DEVELOPER level, it will warn you if you make this mistake. One of the many reasons you should always use developer debug when doing development.