我无法从我的数据库中检索图像

时间:2022-09-03 23:18:55

I have a database containing movies Name, their description and their cover picture. The cover picture field type is as blob and the problem is that I can't retrieve it from the database. I want to display the movie name along their cover picture beside them... How to do it.. Here is my code..

我有一个包含电影名称,他们的描述和封面图片的数据库。封面图片字段类型为blob,问题是我无法从数据库中检索它。我想在他们旁边的封面图片上显示电影名称......怎么做..这是我的代码..

<?php

include ("php/connection.php");
$ID = $_GET['id'];
$listmovies = "SELECT * FROM movies where Genres LIKE '%$ID%'";
$result = mysql_query($listmovies);
while ( $row = mysql_fetch_assoc($result) ) {
    ?>
<table border="1" width="100%">
    <tr>
        <td rowspan="2" width="90" height="120">
<?php

    // set the header for the image
    header("Content-type: image/jpeg");
    echo $row['Image'];

    ?> </td>
        <td width="200" height="10">
<?php

    echo $row['Title'];
    ?></td>
    </tr>
    <tr>
        <td width="200" height="110"><a
            href="php/moredetails.php?id=<?php echo $row['ID']; ?>">More Detail</a></td>
    </tr>
<?php } ?> </table>

I just want to display The Imgaes beside the title of the movie?

我只是想在影片的标题旁边展示Imgaes?

2 个解决方案

#1


2  

Yes it won't display because any output above header would always generate error ... you need to have a different page to output your image or include it has base64 image

是的,它不会显示,因为标题上方的任何输出总是会产生错误...您需要有一个不同的页面来输出您的图像或包含它有base64图像

Remove

去掉

header("Content-type: image/jpeg");
echo $row['Image'];

And add this :

并添加这个:

printf("<img src=\"data:image/jpeg;base64,%s\" />",base64_encode($row['Image']));  
                               ^--- Note this is only for jpeg images

#2


0  

I suggest something like that:

我建议这样的事情:

Make a new php file called for example image.php; That file will replace physical image file. In that file you put the code from your post plus some logic to get image data from database;

制作一个新的php文件,例如image.php;该文件将替换物理图像文件。在该文件中,您将来自帖子的代码加上一些逻辑来从数据库中获取图像数据;

In parent template(php file maybe) you put code for image:

在父模板(也许是php文件)中,您可以为图像添加代码:

<img src="image.php?id_movie=<?php echo $id_movie; ?>" width ="200" height="200" /> More Detail

In image.php i suggest to be careful at spaces outside php tags (at the beniging and at the end). Also to image.php you need to give id of the movie to know what image to load from database.

在image.php中,我建议小心php标签之外的空间(在beniging和结尾)。另外,对于image.php,你需要给出电影的id来知道从数据库加载什么图像。

#1


2  

Yes it won't display because any output above header would always generate error ... you need to have a different page to output your image or include it has base64 image

是的,它不会显示,因为标题上方的任何输出总是会产生错误...您需要有一个不同的页面来输出您的图像或包含它有base64图像

Remove

去掉

header("Content-type: image/jpeg");
echo $row['Image'];

And add this :

并添加这个:

printf("<img src=\"data:image/jpeg;base64,%s\" />",base64_encode($row['Image']));  
                               ^--- Note this is only for jpeg images

#2


0  

I suggest something like that:

我建议这样的事情:

Make a new php file called for example image.php; That file will replace physical image file. In that file you put the code from your post plus some logic to get image data from database;

制作一个新的php文件,例如image.php;该文件将替换物理图像文件。在该文件中,您将来自帖子的代码加上一些逻辑来从数据库中获取图像数据;

In parent template(php file maybe) you put code for image:

在父模板(也许是php文件)中,您可以为图像添加代码:

<img src="image.php?id_movie=<?php echo $id_movie; ?>" width ="200" height="200" /> More Detail

In image.php i suggest to be careful at spaces outside php tags (at the beniging and at the end). Also to image.php you need to give id of the movie to know what image to load from database.

在image.php中,我建议小心php标签之外的空间(在beniging和结尾)。另外,对于image.php,你需要给出电影的id来知道从数据库加载什么图像。