0

I'm trying to get a 1 or a 0 from the result, but how do I retrieve it and use it as a simple variable to compare with other variable? I want to use my variable $result_1 and check if it has the value of 1 or 0.

//
$stmt = $db->prepare("SELECT status FROM todo WHERE id=?");
$stmt->bind_param("i", $id);
$stmt->execute();
$result_1 = $stmt->get_result();
3D-kreativ
  • 9,053
  • 37
  • 102
  • 159

2 Answers2

2

Take a look at the documentation http://php.net/manual/en/mysqli-stmt.get-result.php

In the examples it states that get_result() returns a result set. Which is basically a container for all the rows that came back. They can be aquired by the following procedure.

$result = $stmt->get_result(); $row = $result->fetch_assoc(); $result_1 = $row['status'];

My example assumes that data came back.

Niels
  • 646
  • 3
  • 13
0

You can do it by:

$stmt = $db->prepare("SELECT `status` FROM `todo` WHERE `id` = ?");
$stmt->bind_param("i", $id);
$stmt->execute();
$result_1 = $stmt->get_result();

while($row = $result_1->fetch_assoc()) {
    //do something
    echo row['status'];
}
Adern Nerk
  • 332
  • 3
  • 13