php - Join query in Moodle only returns last column only while mysql returns correctly -
i have 2 tables in moodle database such equiz_details , equiz_responses follows:
mdl_equiz_details:
mdl_equiz_details
i have used join query fetch result desired form follows:
select distinct ed.quizid,ed.questionnumber,ed.questiontext,ed.optiontext1,ed.optiontext2,ed.optiontext3,ed.optiontext4, ed.correctanswer,er.studentanswer `mdl_equiz_details` ed inner join `mdl_equiz_responses` er on ed.quizid = er.quizid , ed.questionnumber = er.questionnumber , er.studentid=4 , er.quizid=25
i fired query in mysql database annd got result follows:
result in mysql
i using same query inside moodle page , try fetch result follows::
<?php require_once('../../config.php'); global $db; $quizresdetails = $db->get_records_sql("select ed.quizid,ed.questionnumber,ed.questiontext,ed.optiontext1,ed.optiontext2,ed.optiontext3,ed.optiontext4, ed.correctanswer,er.studentanswer {equiz_details} ed inner join {equiz_responses} er on ed.quizid = er.quizid , ed.questionnumber = er.questionnumber , er.studentid=4 , er.quizid=25"); var_dump($quizresdetails); ?>
i getting result follows:
result in moodle page
which last result.
what doing wrong? how can fetch full result in moodle page?
moodle version: 2.9.1
the problem query returning same value id in each record: "25". moodle get_records_* methods expect every result have unique id, uses id array key in array of results returns. it's finding results, loops through them adding each result array key "25", when gets end, has last result in returned array.
so need return field unique id each row, "id".
Comments
Post a Comment