How can one optimize the full-text search function in a PHP script to search across multiple fields in a database?

To optimize the full-text search function in a PHP script to search across multiple fields in a database, you can concatenate the fields you want to search into a single column and then perform a full-text search on that column. This allows you to search across multiple fields efficiently without having to perform separate searches on each field.

// Assuming $searchTerm is the search term input by the user

// Concatenate the fields you want to search into a single column
$query = "SELECT * FROM your_table WHERE CONCAT(field1, ' ', field2, ' ', field3) LIKE '%$searchTerm%'";

// Execute the query and fetch the results
$result = mysqli_query($connection, $query);

// Loop through the results and display them
while ($row = mysqli_fetch_assoc($result)) {
    // Display search results
}