LMSouq
moodle-core Open

Join query in Moodle only returns last column only while mysql returns correctly

SA
Santhucool
1 month ago
3 views
Problem Description
I have 2 tables in my moodle database such as equiz_details and equiz_responses as follows: **mdl_equiz_details:** [![enter image description here][1]][1] **mdl_equiz_details** [![enter image description here][2]][2] I have used a join query to fetch result as desired form as follows: SELECT distinct ed.quizid,ed.questionnumber,ed.questiontext,ed.optiontext1,ed.optiontext2,ed.optiontext3,ed.optiontext4, ed.correctanswer,er.studentanswer FROM `mdl_equiz_details` as ed INNER JOIN `mdl_equiz_responses` as er ON ed.quizid = er.quizid and ed.questionnumber = er.questionnumber and er.studentid=4 and er.quizid=25 I fired the query in mysql database annd got result as follows: **Result in mysql** [![enter image description here][3]][3] I am using the same query inside my moodle page and try to fetch result as 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 FROM {equiz_details} ed INNER JOIN {equiz_responses} er ON ed.quizid = er.quizid and ed.questionnumber = er.questionnumber and er.studentid=4 and er.quizid=25"); var_dump($quizresdetails); ?> I am getting the result as follows: **Result in Moodle page** [![enter image description here][4]][4] [1]: https://i.sstatic.net/ci4KT.png [2]: https://i.sstatic.net/93ciA.png [3]: https://i.sstatic.net/uOfSU.png [4]: https://i.sstatic.net/u7zts.png Which is obviously the last result. What I am doing wrong? How can I fetch full result in my moodle page? **Moodle version: 2.9.1**

AI-Generated Solution

Powered by LMSouq AI · GPT-4.1-mini

✓ Solution Ready
Analyzing problem and generating solution…
Was this solution helpful?
Back to Knowledge Base