[英]how to display blob type images stored in MySql database on a jquerymobile template
I have a scenario where images should be displayed in my Jquerymobile template. 我有一个场景,图像应该显示在我的Jquerymobile模板中。 These images come from MySQL database. 这些图像来自MySQL数据库。 Image type is blob type, and I am using PHP to retrieve my data - as follows 图像类型为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);
?>
The values from database are stored in an array, and are being converted to JSON format so that I can call them using the following jquery lines - 来自数据库的值存储在一个数组中,并被转换为JSON格式,因此我可以使用以下jquery行来调用它们-
var url = "retrieve_all.php";
$.getJSON(url, function(json) {
.......
.......
....... }
Once the values are received at this function, am appending them to respective HTML fields using - 在此函数中接收到值后,请使用-将它们附加到相应的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);
});
I am able to understand that the image should NOT be taken as a JSON format. 我能够理解,不应将图像视为JSON格式。 But how can this be dealt? 但是如何解决呢? What should I do in PHP to get my blob image displayed on my page/screen? 我该如何在PHP中将我的Blob图片显示在页面/屏幕上?
Is the approach correct? 方法正确吗?
For this, I checked here for help in the beginning, but my scenario seemed to be different. 为此,我一开始在这里检查了帮助,但情况似乎有所不同。
This is more of notes that will give you a solution, than "click here for results"; 与“单击此处获取结果”相比,更多的是可为您提供解决方案的注释; but try this: 但是尝试一下:
To embed everything in a single response 将所有内容嵌入单个响应中
data:image/jpeg;base64,base_64_encoded_jpeg_goes_here
I have a rough demo of JSON to img elements (with external files). 我有一个JSON到img元素 (带有外部文件)的粗略演示。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.