rvdveen27 Posted May 27, 2015 Share Posted May 27, 2015 Hello all, Is it possible to change the database output? For example I have a selection which puts either 1, 2 or 3 into the database for an answer. Now I want to get that 1, 2 or 3 out of the database again but then I want it in the code to be changed for example to: 1 = yes 2 = no 3 = maybe Could anyone tell me how to do this? Link to comment https://forums.phpfreaks.com/topic/296509-change-database-output/ Share on other sites More sharing options...
Barand Posted May 27, 2015 Share Posted May 27, 2015 SELECT CASE colname WHEN 1 THEN 'Yes' WHEN 2 THEN 'No' ELSE 'Maybe' END as Selection FROM tablename Link to comment https://forums.phpfreaks.com/topic/296509-change-database-output/#findComment-1512715 Share on other sites More sharing options...
Barand Posted May 28, 2015 Share Posted May 28, 2015 Alternatively, you could use an ENUM type column CREATE TABLE `users` ( `id` int(5) NOT NULL AUTO_INCREMENT, `username` varchar(45) DEFAULT NULL, `status` enum('yes','no','maybe') NOT NULL DEFAULT 'no', PRIMARY KEY (`id`) ) ; INSERT INTO users (username,status) VALUES ('Peter', 1), ('Paul', 3), ('Mary', 2); Then when you select mysql> SELECT * FROM users; +----+----------+--------+ | id | username | status | +----+----------+--------+ | 1 | Peter | yes | | 2 | Paul | maybe | | 3 | Mary | no | +----+----------+--------+ Link to comment https://forums.phpfreaks.com/topic/296509-change-database-output/#findComment-1512727 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.