How can photographers effectively integrate their work into a website using PHP?
Photographers can effectively integrate their work into a website using PHP by creating a dynamic gallery that showcases their photos. This can be achieved by storing image file paths in a database and using PHP to retrieve and display these images on the website. Additionally, photographers can add features such as image filtering, pagination, and lightbox functionality to enhance the user experience.
<?php
// Connect to database
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "photography_gallery";
$conn = new mysqli($servername, $username, $password, $dbname);
// Retrieve image file paths from database
$sql = "SELECT image_path FROM images";
$result = $conn->query($sql);
// Display images in a gallery
echo '<div class="gallery">';
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo '<img src="' . $row["image_path"] . '" alt="Photo">';
}
} else {
echo "No images found";
}
echo '</div>';
// Close database connection
$conn->close();
?>