[英]how to insert data into a dynamically created row in a table (html) from database using php and mysqli
[英]How to Display Blob PDF data from mysqli database to your html PHP table
我這里有一個免費的錯誤代碼,說明如何通過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);
?>
您可以使用base64_encode()
將blob數據顯示為pdf:
"<object data=\"data:application/pdf;base64," . base64_encode($row[10]) . " type=\"application/pdf\" ></object>"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.