如何在自定义视图中从数据库中获取图像?

时间:2015-08-24 19:37:30

标签: php mysql

我在名为' Recipe'中创建了一个数据库和一个表,我手动将内容添加到该表中。它还包含一个图像列。

我想显示表并通过JSON传递它。我不知道如何显示图像。

我的代码是:

<?php

include("connection.php");

$query = "SELECT * FROM Recipe";

if ($result=mysqli_query($link, $query)) {
    $number = mysqli_num_rows($result);
    echo "<table cellpadding=\'0' cellspacing='0' class='db-table'><tr>
    <th>Recipe name</th>
    <th>Photo</th>
    <th>Steps</th>
    </tr>";
    while($recipe=mysqli_fetch_assoc($result)){
        echo "<tr>";
        echo "<td>".$recipe['Recipe_name']."</td>";
        echo "<td><img src='".getImage.php?id=1."' width='175' height='200'</td>" ;

        echo "<td>".$recipe['Recipe_steps']."</td>";
        echo "</tr>";
    }

    echo "</table>";
} else {

    echo "It failed";
}


 ?>

2 个答案:

答案 0 :(得分:0)

这条线错了。你忘了把图片网址放在这里。     echo“”;

您没有引用图片网址

echo "<td><img src='".$recipe['imageurl']."' width='175' height='200'></td>";

图片代码未正确关闭。

答案 1 :(得分:0)

尝试更改,错过了,将图片网址放在这里。

<img src='".getImage.php?id=1."' width='175' height='200'

<img src='".$recipe['imageurl']."' width='175' height='200'>