如何在html表中显示moodle数据库中的数据

时间:2014-10-31 05:34:01

标签: php html-table moodle

如何在 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

1 个答案:

答案 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);