How can multiple search queries be implemented on a webpage using PHP and MySQL?
To implement multiple search queries on a webpage using PHP and MySQL, you can use conditional statements to determine which search query to execute based on user input. This can be achieved by checking the value of a variable or form input to decide which SQL query to run. You can then display the results of the search queries on the webpage accordingly.
<?php
// Assuming $conn is the MySQL database connection
// Check if a search query was submitted
if(isset($_POST['search'])) {
$searchTerm = $_POST['searchTerm'];
// Check which search query to run based on user input
if($searchTerm == 'query1') {
$sql = "SELECT * FROM table1 WHERE column1 LIKE '%$searchTerm%'";
} elseif($searchTerm == 'query2') {
$sql = "SELECT * FROM table2 WHERE column2 LIKE '%$searchTerm%'";
}
// Execute the selected query
$result = mysqli_query($conn, $sql);
// Display search results
while($row = mysqli_fetch_assoc($result)) {
// Display search results here
}
}
?>