Home › Forums › Back End › Uploading Form Data to The Database › Reply To: Uploading Form Data to The Database
August 20, 2014 at 7:37 am
#180000
Inactive
@chrisburton Thanks ill do that.
Instead of bombarding this forum with PHP questions i cant find answers to, i was thinking of just posting them on this one forum. So heres another question.
I managed to display the data thats on my database onto the page and the following code works perfectly without any problems, but i’m sure some improvements can be made to make it more reliable/readable. So i was hoping you guys can help me with that.
`
<?php
// Include database connection file
include("php/db-connect.php");
try {
// get database data
$sql = "SELECT TITLE, COVER_URL FROM movies ORDER BY id DESC";
$q = $connect -> query($sql);
$q -> setFetchMode(PDO::FETCH_ASSOC);
} catch( PDOException $e ) {
$e -> getMessage();
echo "Could not retrieve data from the database";
die();
}
<!-- movies -->
<div class="movies-library-container">
<?php while ($row = $q->fetch()): ?>
<div><a href="movie.php"><img src="<?php echo $row['COVER_URL']; ? />" alt="<?php echo $row['TITLE']; ?>" width="151" height="227" class="cover-image"/><h4><?php echo $row['TITLE']; ?></h4></a></div>
<?php endwhile; ?>
</div>