How can SUBSTR be used to filter database records based on their content in PHP?

To filter database records based on their content using SUBSTR in PHP, you can use the SUBSTR function in your SQL query to extract a specific portion of the column value and then compare it with the desired content. This can be useful for searching for records that contain certain keywords or patterns within a text column.

// Assuming $keyword contains the keyword you want to search for
$keyword = "example";

// SQL query to filter records based on content using SUBSTR
$sql = "SELECT * FROM table_name WHERE SUBSTR(column_name, 1, LENGTH('$keyword')) = '$keyword'";
$result = mysqli_query($connection, $sql);

// Fetch and display the filtered records
while ($row = mysqli_fetch_assoc($result)) {
    echo $row['column_name'] . "<br>";
}