get_records_sql returns only one result on Assignment grading page

get_records_sql returns only one result on Assignment grading page

by ramesh verma -
Number of replies: 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 

Average of ratings: -
In reply to ramesh verma

Re: get_records_sql returns only one result on Assignment grading page

by 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.

Average of ratings: Useful (1)
In reply to Cristian Matos

Re: get_records_sql returns only one result on Assignment grading page

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of 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.