title: How to Display data from moodle database in an html table
body: <p>How to Display data from <strong>moodle database</strong> in <strong>html table</strong>.</p>
  
  <p><strong>What I tried..</strong></p>
  
  <pre><code>$all_response = get_response_details($refid);
      if($all_response){
      $all_response = array_values($all_response);
      $responseCount = count($all_response);
      //table
      $table = new html_table();
      $table-&gt;head = array('Name ','email', 'status', 'Grade');   
      for($k=0;$k&lt;$responseCount;$k++)
      {
          $stud_details = get_student_detail($all_response[$k]-&gt;student_id);//student details
          $stud_details = array_values($stud_details);
          $quest_details = get_quetion_by_id($all_response[$k]-&gt;qn_id, $all_response[$k]-&gt;ref_id);
  
          $table-&gt;data = array(array($stud_details[0]-&gt;firstname, $stud_details[0]-&gt;email,  $all_response[$k]-&gt;sub_status, $grade_date));
  
       echo html_writer::table($table);   
      }
  </code></pre>
  
  <p>But the problem is separate tables are displayed for each data. That is if 3 records are there then shows three tables.</p>
  
  <p>I put <code>echo html_writer::table($table);</code> outside the for loop then only one row should be displayed.</p>
  
  <p>I have to display all records in single table. Any help is appreciated....</p>
  
  <p>I am using <strong>Moodle 2.7</strong></p>