How can PHP be used to search for keywords in a MySQL database and then locate corresponding HTML files in a local directory?

To search for keywords in a MySQL database and then locate corresponding HTML files in a local directory using PHP, you can first query the database to retrieve the relevant data based on the keywords. Then, use the retrieved data to locate the corresponding HTML files in the local directory. Finally, you can display or manipulate the HTML files as needed.

<?php
// Connect to MySQL database
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database";
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

// Search for keywords in the database
$keyword = "example";
$sql = "SELECT html_file FROM table_name WHERE column_name LIKE '%$keyword%'";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // Output data of each row
    while($row = $result->fetch_assoc()) {
        $html_file = $row["html_file"];
        // Locate corresponding HTML file in local directory
        $file_path = "path/to/html/files/" . $html_file;
        
        // Do something with the HTML file, such as displaying it
        echo file_get_contents($file_path);
    }
} else {
    echo "No results found.";
}

// Close MySQL connection
$conn->close();
?>