如何在 html表中显示来自 moodle数据库的数据。
我尝试了什么..
$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->head = array('Name ','email', 'status', 'Grade');
for($k=0;$k<$responseCount;$k++)
{
$stud_details = get_student_detail($all_response[$k]->student_id);//student details
$stud_details = array_values($stud_details);
$quest_details = get_quetion_by_id($all_response[$k]->qn_id, $all_response[$k]->ref_id);
$table->data = array(array($stud_details[0]->firstname, $stud_details[0]->email, $all_response[$k]->sub_status, $grade_date));
echo html_writer::table($table);
}
但问题是每个数据都会显示单独的表格。那就是如果那里有3条记录则显示三张表。
我将echo html_writer::table($table);
放在for循环之外,然后只显示一行。
我必须在单个表中显示所有记录。任何帮助表示赞赏....
我正在使用 Moodle 2.7
答案 0 :(得分:0)
你能试试吗
// Add the [] to data and just a single array.
$table->data[] = array($stud_details[0]->firstname, $stud_details[0]->email, $all_response[$k]->sub_status, $grade_date);
}
// Outside the loop.
echo html_writer::table($table);