Reputation: 103
I know a select command for it but it's only temporary. What can i do so it would be permanent? So if theres a record where the firstname is John and the lastname is Smith, in the fullname column, automatically it will generate a data of that record to be John Smith.
Upvotes: 0
Views: 12087
Reputation: 20347
Just use the update command:
UPDATE users SET fullname = CONCAT(firstname, ' ', lastname);
Note that if a user ever changes their first or last name the full name field will become out of date. You might be better off only concatenating them on SELECT.
Upvotes: 0
Reputation: 15307
No point in doing this. You can grab the First Name and Last Name from the Database, and when you need to display Full Name, just concat the two of them. Do not Repeat Data in your Database.
Upvotes: 0
Reputation: 3368
$querystring = "select concat(firstname,' ',lastname) as name from users";
Upvotes: 2
Reputation: 5763
Why do you need to do this? You're denormalizing data by repeating it. I don't know the specifics of your application, but I believe it would be best to calculate the full name in your presentation layer.
If you want some kind of "display name" field (like Outlook), that would still need to be assigned at user entry time so the user could choose.
Upvotes: 0