First of all you should change your mysql_* functions to another functions like PDO & mysqli
About your question is how to generate HTML from your DB data there are multiple of ways
One could be like this
<?php
while ($row = mysql_fetch_array($query)) {
?>
<h1><?php echo $row['columnA']; ?></h1>
<div class="myclass"><?php echo $row['columnb']; ?></div>
<img src="<?php echo $row['columnC']; ?>">
<?php
} ?>
Two could be
<?php
while ($row = mysql_fetch_array($query)) {
$str = "";
$str .= "<h1>".$row['columnA']."</h1>";
$str .= '<div class="myclass">'.$row['columnb'].'</div>';
$str .= '<img src="'.$row['columnC'].'">';
echo $str;
<?php
} ?>
Or you can use a FW wich make it simpler for you
Or you can use a templating library which is the best way for you if you are not going to use a Framework
check out mustache https://github.com/bobthecow/mustache.php
Of course you can change the HTML structure
I hope this can help :)