PHP: Print contents of MySQL table, each row in it's own div
I have a table in MySQL with 5 rows (filename, location, type, author, date) and I would like to use PHP to print something like the following:
<div id="file">
<a href="(location)">(filename)</a> - (author)<br>
(type) - (date)
</div>
I would like a new div to be created for every row in the table, is t开发者_如何学Chis possible?
<?php
while($row = mysql_fetch_assoc($result)){
echo '<div id="file"><a href="'.$row['location'].'">'.$row['filename'].'</a> - a '.$row['author'].'<br>
'.$row['type'].' - '.$row['date'];
}
you need to iterate like so:
<?php $result = mysql_query('SELECT * FROM files;') ?>
<?php while($row = mysql_fetch_assoc($result)) : ?>
<div id="file">
<a href="<?php echo $row['location'] ?>">
<?php echo $row['filename'] ?>
</a>
- <?php echo $row['author'] ?>
<br>
<?php echo $row['type'] ?> - <?php echo $row['date'] ?>
</div>
<?php endwhile ?>
精彩评论