-3

The question is simple, I have a small database and what I would like to compare is a specific column.

Scenario:

Using PHP to get the result from a querie and getting the value:

$sql = "SELECT verified FROM user WHERE id = ?";
$stmt->bind_param("i", $id);
$stmt->execute();

verified is a tinyint, either 0 or 1.

So how using PHP could make an if statement which compares either the result of $stmt->execute(); is 0 or 1.

<? php if(mysqli_fetch_row($stmt) == 0) {
      echo "Not verified"

} else {

      echo "Verified"
}

PD: What I would like to know is how to compare and operate on a SQL query.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Gonzalo
  • 353
  • 2
  • 16
  • You need to get the specific field within the row. The row will be an array of values (as per the manual). Try `if(mysqli_fetch_row($stmt)[0] == 0)` – ADyson Mar 16 '21 at 08:16

1 Answers1

0

You are almost there, jus grab result, and then compare it:

$result = $stmt->get_result();
$row = $result->fetch_array(MYSQLI_ASSOC);

if($row['verified'] == 1){
   echo 'verified';
}else{
   echo 'not verified';
}
Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98