The following code is meant to check if a certain query returns data. The query takes a piece of session data that is searched by the user on another page.
$whatwechecking = $_SESSION ['assignment_searched'];
$FindAsigns = $connection->query("SELECT `NAME`,`DATE`,`GRADE` FROM grades
WHERE `ASSIGNMENT` = '$whatwechecking' ORDER BY `ASSIGN_ID` DESC LIMIT 0,5");
if ($FindAsigns->fetchColumn() > 0) //this is the attempt at seeing if
//the query returned something
{
while($row = $FindAssigns->fetch()) //this loop outputs the data found in the
//query into a table
{
...find data
echo (...echo out data into table);
}
}
else
{
header('Location: NameNotFound.php'); //this is to redirect the user
to an error page that says data was not retreived in the query
}
ideally I'd like to do this in PDO as the query is in the same standard. The fetch rows method I imagine is not the most ideal in this case, so is there a better way to see if the query returns nothing?