Jump to content

Change database output


rvdveen27

Recommended Posts

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

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     |
+----+----------+--------+

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.