This has got me completely staggered.
I have an sql query that retrieves 1 result. I want to make an if statement that says if the result is retrieved do this, else do something else.
I have tried:
$sql = "SELECT * FROM `items` WHERE `teamid` = $teamid ORDER BY `item_id` DESC LIMIT 1";
$sql = $modx->query($sql);
if (is_object($sql)) {
while ($sqlrow = $sql->fetch(PDO::FETCH_ASSOC)) {
$lastitem = $sqlrow['itemname'];
}//WHILE
}//if
else {
$lastitem = "NA";
}//ELSE
but not matter what I do the IF statement is triggered.
I have also tried using isset() and even strlen().
Does anyone know a way to say
'If the SQL statment returned no results from the database'
?
Is the only way to do this with a count?
Many thanks in advance