I am new to moodle I am trying to fetch data from a database and converting it in a Pdf File but the pdf file is empty it doesn't display the database elements. I don't get what am I doing wrong, can you help me?
this is the file with the button that triggers the process
// lib.php
<?php
/**
* @package tool_report
* @author Kristian
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(__DIR__ . '/../../../config.php');
defined('MOODLE_INTERNAL') || die();
$PAGE->set_url(new moodle_url('/admin/tool/report/lib.php'));
$PAGE->set_context(\context_system::instance());
$PAGE->set_title(get_string('manage_reports', 'tool_report'));
//what level of the site where are
echo $OUTPUT->header();
?>
<style media="screen">
.btn {
height: 30px;
width: 60px;
background-color: red;
}
</style>
<form action="manage.php" method="POST">
<button class="btn" type="submit" name="button">PDF</button>
</form>
<?php
echo $OUTPUT->footer();
and this is the file that contains the logic:
//manage.php
<?php
/**
* @package tool_report
* @author Kristian
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require('fpdf/fpdf.php');
ob_start(); //
require_once(__DIR__ . '/../../../config.php');
defined('MOODLE_INTERNAL') || die();
$PAGE->set_url(new moodle_url('/admin/tool/report/manage.php'));
$PAGE->set_context(\context_system::instance());
$PAGE->set_title(get_string('manage_reports', 'tool_report'));
//what level of the site where are
global $DB;
echo $OUTPUT->header();
$sql = " SELECT *
FROM mdl_bigbluebuttonbn
";
$record = $DB->get_record_sql($sql);
//print_r($record);
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Courier','B',16);
$pdf->Cell(50,10,'Course ID', '1', '0', 'C');
$pdf->Cell(50,10,'Course TYPE', '1', '0', 'C');
$pdf->Cell(50,10,'Course COURSE', '1', '0', 'C');
$pdf->Cell(50,10,'Course NAME', '1', '0', 'C');
ob_end_clean();
$pdf->Output();
?><?php
while ($row = mysqli_fetch_assoc($record)) {
print_r($row); die();
?>
<tr>
<td><?php echo $row['id'] ?></td>
<td><?php echo $row['type'] ?></td>
<td><?php echo $row['course'] ?></td>
<td><?php echo $row['name'] ?></td>
</tr>
<?php
}
echo $OUTPUT->footer();
?>