In PHP, what is the significance of using a WHERE clause in a SQL query to retrieve specific user data?

When retrieving user data from a database in PHP using SQL queries, it is important to use a WHERE clause to specify conditions that filter the results and retrieve only the data for a specific user. This ensures that the query returns accurate and relevant information, rather than all user data in the database.

$user_id = 1;

// Connect to database
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

// SQL query with WHERE clause to retrieve user data
$sql = "SELECT * FROM users WHERE id = $user_id";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // Output data of each row
    while($row = $result->fetch_assoc()) {
        echo "User ID: " . $row["id"]. " - Name: " . $row["name"]. " - Email: " . $row["email"]. "<br>";
    }
} else {
    echo "0 results";
}

$conn->close();