I want to run a query against my database and would like to have a specific image (icon) displayed in the table cell. I am new to SQL and am trying to determine how I might set this up using a standard table panel.
I want to iterate over all rows in the table and display an image (icon) based on the value of a cell. This is what I have set up so far and it works when I check “sanitize HTML” in the column styles tab within the table settings. I am aware that this will only output the same image in all cells within the column.
select '<img src="IMAGE_URL" />' as item FROM myTable where status_code = 1
Now I need to modify this to return different HTML tags based on the various codes that will get returned. I have this set up as follows but am not getting the images output.
SELECT status_id CASE WHEN status_id = 1 THEN '<img src="IMAGE_URL1" />' WHEN status_id = 2 THEN '<img src="IMAGE_URL2" />' WHEN status_id = 3 THEN '<img src="IMAGE_URL3" />' ELSE 0 END AS "Utilities" FROM myTable
Am I even going about this the right way or is there a better method to achieve this?
UPDATE: SOLVED The above example did work as expected the issue was in the database. I was using INT for the status_id and since I am using HTML to insert into the table (set to a string and sanitizing HTML) that was not compatible with INT, so updating DB column to be character_varying solved the problem.