Jump to content
mahenda

show me a way to convert mysql table to pdf or text document when user click download button mysql procedural

Recommended Posts

create table mimi (mimiId int(11) not null, mimiBody varchar(255) );
<?php
//connecting to database
include_once ('conn.php');
$sql ="SELECT mimiId, mimiBody FROM mimi";

$result = mysqli_query($conn, $sql );

$mimi = mysqli_fetch_assoc($result);

$mimiId ='<span>No: '.$mimi['mimiId'].'</span>';

$mimiBody ='<p class="leading text-justify">'.$mimi['mimiBody'].'</p>';
?>
//what is next?

i want to download pdf or text document after clicking button or link how to do that

Share this post


Link to post
Share on other sites

As you put your data inside HTML tags I assue that by text file you mean an html text file. (Neither plain text nor PDF use html tags.

The easier option is the text one. Add this code

$mycontent = <<<TEXT
<!DOCTYPE=html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Sample output</title>
</head>
<body>
    $mimiId
    $mimiBody
</body>
</html>
TEXT;

header('Content-Type: text/html');
header('Content-Disposition: attachment; filename="mytest.html" ');
header('Pragma: no-cache');
header('Expires: 0');
echo $mycontent;

if you want pdf, that is more complicated. I suggest you visit the FPDF site. Lots of example there.

Share this post


Link to post
Share on other sites
7 minutes ago, Barand said:

As you put your data inside HTML tags I assue that by text file you mean an html text file. (Neither plain text nor PDF use html tags.

The easier option is the text one. Add this code


$mycontent = <<<TEXT
<!DOCTYPE=html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Sample output</title>
</head>
<body>
    $mimiId
    $mimiBody
</body>
</html>
TEXT;

header('Content-Type: text/html');
header('Content-Disposition: attachment; filename="mytest.html" ');
header('Pragma: no-cache');
header('Expires: 0');
echo $mycontent;

if you want pdf, that is more complicated. I suggest you visit the FPDF site. Lots of example there.

thanks

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.