如何从数据库中回显html和行

时间:2014-04-17 06:41:42

标签: php html mysql echo

我编写了一个脚本来根据当前会话用户从我的数据库中获取一行,该用户正确输出行,但我想插入一个小图像以显示在echo'd行的旁边,并且无法弄清楚正确的语法。

if ($row['lifetime']!="")
echo "<div style ='font:12px Arial;color:#2F6054'> Lifetime Member: </div>     ".$row['lifetime'];
else
echo '';
?>

基本上我希望图像出现在。$行之前或之后,或者是。

3 个答案:

答案 0 :(得分:0)

只需将图片的HTML放入您正在回复的字符串中:

echo "<div style ='font:12px Arial;color:#2F6054'><img src="fill in URL here"> Lifetime Member: </div>     ".$row['lifetime'];

答案 1 :(得分:0)

您可以尝试:

<?php
if ($row['lifetime'] !== "") {
    echo "<div style ='font:12px Arial;color:#2F6054'> Lifetime Member: </div>";
    echo $row['lifetime'];
    echo "<img src='' alt='' style='width:100px'/>";
} 
?>

答案 2 :(得分:0)

您可以尝试以下示例

<强> HTML

<table>
     <thead>
         <tr>
         <th>No.</th>
         <th>Customer Name</th>
         <th>Photo</th>
         <th ></th>
         </tr>
     </thead>
     <tbody>
        <?php
            $tst=0;
            $result = mysql_query("select * from acc_cust");
            while($row = mysql_fetch_array($result))
                {
                    echo "<tr class='odd gradeX'>";
                    echo "<td width=5%'>" . $row['ent_no']. "</td>";
                    echo "<td>" . $row['cust_name']. "</td>";
                    echo "<td><img src='[path]" . $row['cust_img'] . "' /></td>";
                }
        ?>
    </tbody>
</table>
相关问题