我正在使用 jquery mobile 构建一个 webapp,我一直在尝试从 MySQL DB 显示一个 BLOB PNG 图像,但没有成功。我想知道我做错了什么。
这是我的 popup_data.php
<?php
$con = mysqli_connect('127.0.0.1','root' , '' , 'parkinglot');
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$index_data = 1;
$tables = "show tables";
$result = mysqli_query($con,$tables);
while($row = mysqli_fetch_array($result,MYSQLI_NUM))
{
echo '
<div data-role="popup" id="mapdata'.$index_data.'" class="ui-content" data-theme="a"> ';
echo '<img src="showimage.php?sensor_num='.$index_data.'" />'; //sensor_num is to retrieve the image with that ID
echo '
</div>
';
$index_data++;
};
?>
这是我的 showimage.php
<?php
$con = mysqli_connect('127.0.0.1','root' , '' , 'parkinglot');
// CHECK CONNECTION
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sensor_num = (isset($_GET['sensor_num']) && is_numeric($_GET['sensor_num'])) ? intval($_GET['sensor_num']) : 0;
$data = "SELECT * FROM $table_name2 WHERE sensor_num=$sensor_num";
$result2 = mysqli_query($con,$data);
while ($row2 = mysqli_fetch_array($result2))
{
$imgData = $row2['picture'];
}
header('Content-Type: image/png');
echo $imgData;
?>