John John - 9 months ago 24
MySQL Question

How to setup an if condition in the event no result is returned?

Good day,

I have the following query:

// Add email later on
let sqlSelectBoxInformation = "SELECT DISTINCT longestDimension, box_id from box WHERE occupied ='unoccupied'";

connectionBoxInformation.query(sqlSelectBoxInformation, function(err, rows, fields) {

if (!err) {
// Check to see if the user entered hashtag is found in the database
// Create a variable to track if the item was found

var data = {
rows: rows,
userHashtag: databaseHashtag
res.render('delivery/chooseBox', data);

// Change the variable to true
wasFound = true;


In the event that no results is returned because no result could satisfy those requirements, I would like to have an else statement that would render the user to another page, but I am not too sure how I would proceed.

Vic Vic
Answer Source

What module is that? I'm going to assume this is what you need.

    if(rows.length > 0){