Domanda

I have a script written to grab a row from my database based on current session user, which outputs the row correctly, however I want to insert a small image to be displayed alongside of the echo'd row, and cannot figure out the proper syntax.

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

basically I want the image to appear right before or after the .$row appears, either or.

È stato utile?

Soluzione

You can try:

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

Altri suggerimenti

Just put the HTML for the image into the string you're echoing:

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

You can try as below example

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>
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top