I want to fetch data from db in the form of table and generate pdf or excel of that data and want to send it to the user by email directly using php and sql.
Someone please help to solve me this problem. I dont want anyone to write code for me but give me some suggestions to solve it.
<?php
session_start();
include ('db.php');
$db_link=mysqli_connect($hostname, $dbuser, $dbpassword,$dbname) or die("Unable to connect to the server!");
define('FPDF_FONTPATH','../font/');
require('fpdf.php');
$pdf=new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',10);
$pdf->Cell(25,7,"answerid");
$pdf->Cell(30,7,"email");
$pdf->Cell(30,7,"qst");
$pdf->Cell(30,7,"answer");
$pdf->Ln();
include ('db.php');
$db_link=mysqli_connect($hostname, $dbuser, $dbpassword,$dbname) or die("Unable to connect to the server!");
$sql = "SELECT answerid,email,qst,answer FROM responses where email='".$_SESSION['usr_id']."'";
$result = mysqli_query($db_link,$sql);
while($rows=mysqli_fetch_array($result))
{
$id = $rows['answerid'];
$email = $rows['email'];
$question = $rows['qst'];
$answer = $rows['answer'];
$pdf->Cell(25,7,$id);
$pdf->Cell(30,7,$email);
$pdf->Cell(30,7,$question);
$pdf->Cell(30,7,$answer);
}
$pdf->Output();
?>