I need your help with my homework: I'm setting up a project wich genetate pdf certficat for a list of student sroted on a mysql database. For the pdf generator, I used fpdf and I have any problem with that. But for the interface I displayed the data on a table and added a button on each row to print data on the pdf.

so what I whant is that, when the user click on the button 'print' each data in this row is stored on a variable tha I can reuse on the script that provide the pdf.

while($res = mysqli_fetch_array($result)) {         
    echo "<tr>";
    echo "<td>".$res['ID']."</td>";
        echo "<td>".$res['Name']."</td>";
        echo "<td>".$res['Parcours']."</td>";
    echo "<td>".$res['Appreciation']."</td>";
    echo "<td>".$res['SingDate']."</td>";
    echo "<td><input type='submit' id='print' class='btn btn-outline-info waves-effect' value='Print'/></td>";
}

1 Answers

0
Barmar On

Put the ID in the value of the submit button. Then the script that you can submit to can get the value of the button that they used to submit the form.

echo "<td><input type='submit' name='printID' class='btn btn-outline-info waves-effect' value='{$res['ID']}'/></td>";

In the form's action script, use $_POST['printID'] or $_GET['printID'] to get the ID that they selected to print. It can look up the rest of the information about the student in the database using this ID.

$stmt = $mysqli->prepare("SELECT Name, Parcours, Appreciation
    FROM students
    WHERE ID = ?");
$stmt->bind_param("i", $_GET['printID']);
$stmt->execute();
$stmt->bind_result($name, $parcours, $appreciation);
$stmt->fetch();

$pdf->addPage('L'); 
$pdf->useImportedPage($pageId, 10, 10); 
$pdf->SetTextColor(54, 90, 168); 
$pdf->SetFont('Times','i',18); 
$pdf->Text(38,95.6, $name); 
$pdf->Text(38,135.2, $parcours); 
$pdf->Text(106,175.3, $appreciation);

Replace students with the actual name of your table.