想要在查询中使用多个引号显示数据库中的图像

时间:2018-03-17 23:22:20

标签: php mysql

$query = mysql_query("SELECT * FROM `Rorschach` WHERE Rid = $init");
$query2 = mysql_fetch_array($query);
    //$repd = $rep2[0];
$rid = $query2[0];
$rname = $query2[1];
$rimage = $query2[2];
echo '<div class='tab-pane active' id='profile'>
            <table class='table'>
                <tbody>
                    <tr>&nbsp;$rimage
                        <td class='td-actions text-right'>
                            <img src="data:image/jpeg;base64,'.base64_encode($rimage['Rimage'] ).'" height="200" width="200" class="img-thumnail" />
                                <div class='radio'>
                                    <label>
                                       <font color='#777'>True</font> <input type='radio' name = '' value = '1'>
                                    </label>
                                    <label>
                                       <font color='#777'>False</font> <input type='radio' name = '' value = '0'>
                                    </label>
                                </div>



                        </td>
                    </tr>
                </tbody>
            </table>
        </div>';

当我使用$rimage时,它会显示没有编码的图像,所以它没用。 当我使用<img src="data:image/jpeg;base64,'.base64_encode($rimage['Rimage'] ).'" height="200" width="200" class="img-thumnail" />时,Echo命令不执行此行,因为有多个引号。

DB:

Rid || Rname || Rimage
====+========+=========
 1  ||  abc  || img.jpg

1 个答案:

答案 0 :(得分:0)

这不是那条线的问题。你需要改变几乎所有东西。

echo '<div class='tab-pane active' id='profile'>中,您以单引号打开echo。这意味着除了任何PHP代码之外,HTML中的所有其他内容(如类)都需要使用双引号。如果您使用双引号打开echo,则HTML中的所有内容都将使用单引号,但任何PHP代码除外。

请尝试使用此echo语句,因为这应该可以正常使用:

echo '<div class="tab-pane active" id="profile">
    <table class="table">
            <tbody>
                <tr>&nbsp;'.$rimage.'
                    <td class="td-actions text-right">
                        <img src="data:image/jpeg;base64,'.base64_encode($rimage['Rimage'] ).'" height="200" width="200" class="img-thumnail" />
                        <div class="radio">
                            <label>
                               <font color="#777">True</font> <input type="radio" name = " " value = "1">
                            </label>
                            <label>
                               <font color="#777">False</font> <input type="radio" name = " " value = "0">
                            </label>
                        </div>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>';