I am trying this code but i want to know what is the number of results of this query. If do the same query in mysql console I get 4 results, but with this code I get 0 rows.
What is the correct way to get the number of rows ?
function check_oferta_existe($db, $id, $id_oferta) {
$sql = $db -> prepare("
SELECT COUNT(offer)
FROM offer
WHERE company_users_id_user1 = ? AND offer = ? AND state = 0
");
$sql -> bind_param('is', $id, $oferta);
$sql -> execute();
$sql -> fetch();
$sql->store_result();
$rows = $sql->num_rows;
var_dump($rows); // 0, should be 4
if ($rows == 1) {
return true;
}
else {
return false;
};
}
I see two errors in your code. When you do this statement:
you use
$ofertabut seems (looking at the function parameters) that the var should be$id_oferta.Moreover, after the closing bracket of your
elseyou have a semicolon which should not be there.