How can one efficiently display table data in PHP based on specific search criteria?

To efficiently display table data in PHP based on specific search criteria, you can use SQL queries to retrieve only the data that matches the criteria. You can then loop through the results and display them in a table format using HTML.

<?php
// Connect to your 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);
}

// Define your search criteria
$search_criteria = "example";

// Query to retrieve data based on search criteria
$sql = "SELECT * FROM table_name WHERE column_name = '$search_criteria'";
$result = $conn->query($sql);

// Display data in a table format
if ($result->num_rows > 0) {
    echo "<table>";
    echo "<tr><th>Column 1</th><th>Column 2</th></tr>";
    while($row = $result->fetch_assoc()) {
        echo "<tr><td>" . $row["column1"] . "</td><td>" . $row["column2"] . "</td></tr>";
    }
    echo "</table>";
} else {
    echo "No results found.";
}

$conn->close();
?>