3
I’m trying to assign a value to a variable when the search return is NULL
, but I’m not getting it, when I check the value of the variable $IdSetor
she is NULL
and not zero, as I need.
The research and what I’m trying to do:
// BUSCANDO IdSetor
$sqlVerSetor = "SELECT IdSetor FROM cadSetor WHERE IdSetorOld = ?";
$stm = $conexao->prepare($sqlVerSetor);
// DEFINE O TIPO DA VARIÁVEL INT OU STR
$stm->bindValue(1, $LotacaoRH, PDO::PARAM_INT);
$stm->execute();
$ResDadosSetor = $stm->fetchAll(PDO::FETCH_OBJ);
// CONTAGEM DE REGISTROS RETORNADOS
$conSqlRegSetor = count($ResDadosSetor);
// FECHANDO A CONSULTA
$stm->closeCursor();
foreach($ResDadosSetor as $RegSetor) {
$IdSetor = $RegSetor->IdSetor;
if ($IdSetor == NULL) {
$IdSetor = 0;
} else {
$IdSetor = $IdSetor;
}
}
I will put an image of my query, even with the tips given I still could not do what I need, but forgot to mention that my query generates an empty set of records, see:
That one
else
is it really necessary? hehe– Woss
rsrs... had not even noticed
– Sam
@dvd, if the return is not null need to burn the returned value.
– adventistapr
@adventistapr Vc would not want to assign 0 to $Idsetor if it were null?
– Sam
@adventistapr I updated the answer. See if this is what I wanted.
– Sam
That’s right @dvd, I appreciate the help.
– adventistapr