我这里有一个免费的错误代码,该代码说明如何通过php将数据库中的所有数据显示到html表中,但我不仅要显示字符和数字,还希望显示BLOB数据,例如Pdf,Image,Txt还有更多,你们能帮助我吗,btw是php和mysqli的新手,$ row [10]是我设置为BLOB数据类型的字段,在此先感谢大家,我爱你们所有人!
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "recordmain_db" ;
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($conn,"SELECT * FROM recordmain_table");
echo "<center><table id=myTable table border=8 cellspacing=1
cellpadding=5>";
echo "<tr class='header'>
<th>Doc Type</th>
<th>Doc Date</th>
<th>Date Sent</th>
<th>Medium of Transaction</th>
<th>Description</th>
<th>Receiver</th>
<th>Address</th>
<th>Contact</th>
<th>Attachment</th>
<th>File</th>
</tr>";
?>
<?php
while($row = mysqli_fetch_array($result))
{
echo
"<tr>
<td>" . $row[1] . "</td>
<td> " . $row[2] . "</td>
<td>" . $row[3] . "</td>
<td>" . $row[4] . "</td>
<td>" . $row[5] . "</td>
<td>" . $row[6] . "</td>
<td>" . $row[7] . "</td>
<td>" . $row[8] . "</td>
<td>" . $row[9] . "</td>
<td>" . $row[10] . "</td>
</tr>";
}
echo "</table></center>";
mysqli_close($conn);
?>
答案 0 :(得分:1)
您可以使用base64_encode()
将blob数据显示为pdf:
"<object data=\"data:application/pdf;base64," . base64_encode($row[10]) . " type=\"application/pdf\" ></object>"