Revolutsio Posted December 18, 2019 Share Posted December 18, 2019 Hi I have a database with all my game collection on and have the code to display it on a webpage, my problem is in one field called Media, i have the text 'Physical' in it and i would like to change this within PHP to an image of a floppy disk when it displays on the webpage. Can this be done. I have done something similar with and if statement to display a 'tick' instead of a 1. IF ( owned = 1, '✔', 'X' ) AS owned, IF ( completed = 1, '✔', ' ' ) AS completed i would like to do this as above rather than adding it to the MySQL database - the floppy image is on my computer in a folder called Images. Quote Link to comment https://forums.phpfreaks.com/topic/309706-swapping-text-to-an-image/ Share on other sites More sharing options...
Barand Posted December 18, 2019 Share Posted December 18, 2019 (edited) if you want to do it in the query (as you have above) then something like SELECT IF(Media='Physical', '<img src="images/floppy.png">', Media) as Media Edited December 18, 2019 by Barand Quote Link to comment https://forums.phpfreaks.com/topic/309706-swapping-text-to-an-image/#findComment-1572618 Share on other sites More sharing options...
Revolutsio Posted December 18, 2019 Author Share Posted December 18, 2019 Hi thank you for your reply, I have tried the above code and I get a error Parse error: syntax error, unexpected 'Images' (T_STRING) here is my Select code <?php $sql = "SELECT ID, GAME, YEAR, PLATFORM, PUBLISHER, Owned, COMPLETED, Media, Launcher, IF(Media='Physical', '<img src="Images/floppy.png"">', Media) as Media FROM games;"; Quote Link to comment https://forums.phpfreaks.com/topic/309706-swapping-text-to-an-image/#findComment-1572619 Share on other sites More sharing options...
Barand Posted December 18, 2019 Share Posted December 18, 2019 Escape the quotes. IF(Media='Physical', '<img src=\"Images/floppy.png\">', Media) as Media Quote Link to comment https://forums.phpfreaks.com/topic/309706-swapping-text-to-an-image/#findComment-1572621 Share on other sites More sharing options...
Revolutsio Posted December 18, 2019 Author Share Posted December 18, 2019 Thank you for your help Quote Link to comment https://forums.phpfreaks.com/topic/309706-swapping-text-to-an-image/#findComment-1572624 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.