我有一个场景应该在我的 Jquerymobile 模板中显示图像。这些图像来自 MySQL 数据库。图像类型是blob类型,我正在使用PHP来检索我的数据-如下
<?php
include 'configure.php';
$qr = "SELECT * FROM food_beverage";
$res= mysql_query($qr);
$i=0;
while($row = mysql_fetch_array($res))
{
$restau_arr[$i]["fb_sno"] = $row["fb_sno"];
$restau_arr[$i]["fb_name"] = $row["fb_name"];
$restau_arr[$i]["fb_type"] = $row["fb_type"];
$restau_arr[$i]["fb_location"] = $row["fb_location"];
$restau_arr[$i]["fb_img"]= $row["fb_img"];
$restau_arr[$i]["fb_phno"]= $row["fb_phno"];
$restau_arr[$i]["fb_email"]= $row["fb_email"];
$i++;
}
header('Content-type: application/json');
echo json_encode($restau_arr);
?>
数据库中的值存储在一个数组中,并被转换为 JSON 格式,以便我可以使用以下 jquery 行调用它们 -
var url = "retrieve_all.php";
$.getJSON(url, function(json) {
.......
.......
....... }
在此函数中接收到值后,我将它们附加到相应的 HTML 字段中,使用 -
$.each(json, function(i,v) {
var restauName = v.fb_name;
var restauLoc = v.fb_location;
var restauNum = v.fb_phno;
var restauImg = v.fb_img;
$("#restauName").html(restauName);
$("#restauLoc").html(restauLoc);
$("#restauNum").html(restauNum);
$("#restauImg").html(restauImg);
});
我能够理解图像不应被视为 JSON 格式。但如何处理呢?我应该在 PHP 中做什么才能让我的 blob 图像显示在我的页面/屏幕上?
方法是否正确?
为此,我一开始就在这里寻求帮助,但我的情况似乎有所不同。