What are common methods for selecting data from a database where one field is equal and another is not in PHP?

When selecting data from a database where one field is equal and another is not in PHP, you can use a SQL query with the WHERE clause to specify the condition for the field that should be equal and another condition using the NOT operator for the field that should not be equal. This allows you to filter the results based on these criteria.

// Connect to the database
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database";

$conn = new mysqli($servername, $username, $password, $dbname);

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

// Select data where one field is equal and another is not
$sql = "SELECT * FROM table_name WHERE field1 = 'value1' AND field2 != 'value2'";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
  // Output data of each row
  while($row = $result->fetch_assoc()) {
    echo "Field1: " . $row["field1"]. " - Field2: " . $row["field2"]. "<br>";
  }
} else {
  echo "0 results";
}

$conn->close();