Jump to content

Change database output


rvdveen27
Go to solution Solved by Barand,

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
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     |
+----+----------+--------+
Edited by Barand
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.