簡體   English   中英

如何從數據庫中回顯HTML和行

[英]How to echo html and row from database

我編寫了一個腳本,用於根據當前會話用戶從數據庫中獲取行,該腳本可以正確輸出該行,但是我想插入一個小圖像以在回顯行的旁邊顯示,並且無法找出正確的語法。

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

基本上,我希望圖像顯示在。$ row出現之前或之后。

只需將圖像的HTML放入要回顯的字符串中即可:

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

你可以試試:

<?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'/>";
} 
?>

您可以嘗試以下示例

的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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM