How to put text below photo

I want add text just below the picture but I don't know how to do it.

Example

<?php


include "includes/connexio_web.php";
obrirConnexioBD();
$sql = "SELECT * FROM Llistat_vies";
$sth = $conn->query($sql);

while($row=mysqli_fetch_array($sth)) {
        echo "<tr>";
        echo "<td>"; ?> 
        <img src="<?php echo $row["photo"]; ?>" height="200" width="200"><?php echo "</td>";
        echo "<td>"; echo $row["text"]; echo "</td>";
        echo "</tr>";
    }
?>

Upvotes: 0

Views: 48

Answers (3)

Genesis
Genesis

Reputation: 1

I am pretending that your <table> and <tr> are outside of the loop.

<table>
<tr>

while($row=mysqli_fetch_array($sth)) {

        echo "<td>";
        echo "<table>";
        echo "<tr>";
        echo "<td>";
        ?>
          <img src="<?php echo $row["photo"]; ?>" height="200" width="200">
        <?php
        echo "</td>";
        echo "</tr>";
        echo "<tr>";
        echo "<td>";
        echo $row["text"];
        echo "</td>";
        echo "</tr>";
        echo "</table>";
        echo "</td>";
    }
</tr>
</table>

I put tables within the table an inside of a <td> so that they would be next to each other.

I don't know if this is the best way but it was similar to what you were doing and it worked for me. I hope this helps.

Upvotes: 0

DesiHacker
DesiHacker

Reputation: 106

try these new HTML5 tags: <figure> and <figcaption>

Put your image and text inside these tags like this:

    echo "<tr>"; 
    echo "<td>"; ?> 
    <figure>
    <img src="<?php echo $row["photo"]; ?>" height="200" width="200">
    <figcaption>
    <?php  echo $row["text"];
   echo "</figcaption>";
   echo "</figure>";
    echo "</td>";
    echo "</tr>";

Upvotes: 0

Vidal
Vidal

Reputation: 2606

Here your code updated.

<?php

   include "includes/connexio_web.php";
        obrirConnexioBD();
    $sql = "SELECT * FROM Llistat_vies";
        $sth = $conn->query($sql);
     $table= "<table>";
    while($row=mysqli_fetch_array($sth)){
       $table= "<tr>
          <td align='center'> 
            <img src=".$row["photo"] ." height='200' width='200'> <br>
            $row["text"]
          </td>
       </tr>";

    }

print $table . "</table>";
?>

Upvotes: 1

Related Questions