user272899
user272899

Reputation: 851

How to display query results in an HTML page

When showing data from a mysql table on an php page does it have to be in a table??

What I want to do is display my results in divs.

like so:

  <div class="moviebox rounded"><a href="">
  <img src="  $imgurl  " />
  <form method="get" action="">
 <input type="text" name="link" class="link" style="display:none" value="http://us.imdb.com/Title?   $imdburl      "/>
 </form>
  </a></div>

And have that repeat for each one of the images in the database. How is this done?? I am fine showing the data in a table but can't seem to get this right

Upvotes: 0

Views: 5922

Answers (3)

rodrigoap
rodrigoap

Reputation: 7480

like this

<?php
    $result = mysql_query("SELECT imageURL from ...");
    while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
        ?>
            <div>
                <img src="<?php echo $row['imageURL']; ?>" />
            </div>
        <?php
    }
?>

Upvotes: 1

Lucas Jones
Lucas Jones

Reputation: 20193

Try:

<div class="moviebox rounded"><a href="">
  <img src="<?= $imgurl ?>" />
  <form method="get" action="">
 <input type="text" name="link" class="link" style="display:none" value="http://us.imdb.com/Title?<?= $imdburl ?>"/>
 </form>
  </a></div>

Upvotes: 0

Quentin
Quentin

Reputation: 943564

When showing data from a mysql table on an php page does it have to be in a table??

No, it is just data. You can describe it using whatever markup you like. A table is often a good choice, but not always.

  <div class="moviebox rounded"><a href="">
  <img src="  $imgurl  " />
  <form method="get" action="">

a elements cannot contain form elements (or any other block element)

Upvotes: 3

Related Questions