【发布时间】:2013-08-20 21:42:18
【问题描述】:
我有一个场景应该在我的 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 图像显示在我的页面/屏幕上?
方法正确吗?
为此,一开始我checked here寻求帮助,但我的情况似乎有所不同。
【问题讨论】: