This post has been de-listed
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
1
Failing to fetch data from a database and converting it in pdf
Post Body
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
<?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>
<h1>hi</h1>
<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:
<?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();
?>
Post Details
We try to extract some basic information from the post title. This is not
always successful or accurate, please use your best judgement and compare
these values to the post title and body for confirmation.
- Posted
- 3 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/moodle/comm...