How to Use the WHERE Clause in PHP MySQL?

03-Apr-2023

.

Admin

How to Use the WHERE Clause in PHP MySQL?

Hi Dev,

This tutorial is focused on how to use a where clause in PHP MySQL. you'll learn how to use a where clause in a PHP MySQL. We will use how to use the where clause in PHP MySQL. if you have a question about how to use the where clause in PHP MySQL then I will give a simple example with a solution.

Now, let's see the article on how to use the where clause in PHP MySQL. it's a simple example of how to use the where clause in PHP MySQL. you can understand the concept of how to use a where clause in a PHP MySQL. if you have a question about how to use a where clause in PHP MySQL then I will give a simple example with a solution.

Example:


index.php

<?php

$servername = "localhost";

$username = "root";

$password = "root";

$dbname = "myDB";

// Create a connection

$conn = mysqli_connect($servername, $username, $password, $dbname);

// Check the connection

if (!$conn) {

die("Connection failed: " . mysqli_connect_error());

}

$sql = "SELECT id, firstname, lastname FROM MyGuests WHERE lastname='Doe'";

$result = mysqli_query($conn, $sql);

if (mysqli_num_rows($result) > 0) {

// output data of each row

while($row = mysqli_fetch_assoc($result)) {

echo "Name:" . $row["firstname"].;

}

}else {

echo "0 results";

}

mysqli_close($conn);

?>

Output:

Name: John

I hope it could help you...

#PHP