I am trying to develop a search algorithm. This is a problem I am facing right now.
name | Location |
---|---|
First | location 1 |
Second | location 2 |
My Answer:
Yes, you can fetch the value of the column that was matched in the WHERE clause by using the SELECT statement along with the WHERE clause. Here is an example query that demonstrates this:
php
$query = "SELECT name, Location FROM your_table WHERE name = 'First'";
$result = mysqli_query($connection, $query);
if(mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_assoc($result)) {
echo "Name: " . $row['name'] . "
";
echo "Location: " . $row['Location'] . "
";
}
} else {
echo "No results found.";
}
In this example, the query fetches the `name` and `Location` columns from the table where the `name` column matches 'First'. You can then access the values of the matched columns in the `$row` array.
Rate this post
3 of 5 based on 3614 votesComments