0

How can one display an alternative text if there is no record in the database table?

I want to display a placeholder text if there is no data entered in a MySQL database table? I only managed to display when there's something within a table row with the IF, OR , AND and the WHERE conditions. For example: SELECT * FROM table WHERE row id=id number. Now I want something like "Nothing to show" if there is no record at all. Using the above query couldn't display anything since there is no id found in the table.

15th Jan 2022, 3:58 PM
LUTANGU CRISPINE
LUTANGU CRISPINE - avatar
2 Réponses
+ 1
Hi Chris Lutangu , you can do something like SELECT CASE WHEN Count(rowid) > 0 THEN 'records present' ELSE 'Nothing to show' From table WHERE rowid='23'; But, it makes no sense to do this SQL is not a language written to interactively display things, we normally use some backend framework e.g. spring, nodejs, etc. Which talks to the database and can return result according and then a front end written in angular, react or even pure JavaScript which displays this interactively In short, the function of SQL is to view, add or modify data but it is not used to interactively view it
15th Jan 2022, 5:39 PM
Pulkit Kamboj
Pulkit Kamboj - avatar
+ 2
Thanks for the response, I really have been helped.
15th Jan 2022, 8:07 PM
LUTANGU CRISPINE
LUTANGU CRISPINE - avatar