Empty Data Not Reacting!

Hi. I have an SQL database that populates a dropdown list. The contents of the list is controlled by customers booking and attending events. The dropdown list shows current and upcoming events. The list can be empty when the event has occurred and there are no more booked. I would like to display a message in the dropdown list when there are no more events i.e. the list is empty. Here’s my issue. I have tried if/then statements using: CASE WHEN - in the sql, EMPTY/!EMPTY, strLen, trim - strLen, ISNULL, ISSET.

None of these will return a message when there is no data. I don’t know how to show a message when there is no data when the coding itself doesn’t recognise when there is no data.

I really hope this makes sense and that someone can explain what I’m doing wrong.

Many thanks

Andrew

What flavor of SQL are you using?

1 Like

It is MySql 5.7 standard

And what programming language are you using to query.

EDIT: If you need to handle this on the SQL side, you can try adding a COUNT() aggregate to your query and if you need to handle this on the application side, you can check the length of the select options, e.g. in JavaScript it would be: document.getElementById("theSelectId").options.length. Since you haven’t provided your programming language, I can’t be more specific.

Hi dhess

Thanks for replying.

I’ve tried a Case When Then in the sql query but prefer the php If Then statements. Neither of them worked when there is no data to return. I just can’t understand why I can’t use a mechanism to detect no data. It must be possible so I must be doing something wrong but I just can’t see it. Is there another way to look at it? All I want is a default message to appear when there is no data to return.

Cheers

I suggest doing a search for “php get record count from query”.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.