Jim R Posted September 3, 2010 Share Posted September 3, 2010 Is it possible to set a default value for a column based on what is entered in other columns? Example: Column A: nameFirst Column B: nameLast Column C: 'nameFirst'-'nameLast' So as I type in the A and B, C self populates. I see in my column properties, there is a Default option, but I'm not sure I can put variables in there from other columns. Link to comment https://forums.phpfreaks.com/topic/212405-setting-a-default-value-for-a-column/ Share on other sites More sharing options...
trq Posted September 3, 2010 Share Posted September 3, 2010 You would need to do this within your actual insert statement. Link to comment https://forums.phpfreaks.com/topic/212405-setting-a-default-value-for-a-column/#findComment-1106685 Share on other sites More sharing options...
trq Posted September 3, 2010 Share Posted September 3, 2010 Actually, thinking about it a little more. Column C would be just a waste of space in your example. You can easily enough combine Column's A & B whenever you do your data retrieval. Link to comment https://forums.phpfreaks.com/topic/212405-setting-a-default-value-for-a-column/#findComment-1106686 Share on other sites More sharing options...
Jim R Posted September 3, 2010 Author Share Posted September 3, 2010 I figured that would be one of the responses. What I'm trying to do is create within my database a value to match WordPress slugs in a separate data table I use for personal information for basketball players. It works very well. Just that each year, I enter about 150 names at one setting, and it would be nice to have some of it auto-populate. I put their personal information on their Tag Archive page, so as you click on their tag to see everything they're tagged in, you see their height, school, position, school coach's name, and anything else I choose to put in there. Link to comment https://forums.phpfreaks.com/topic/212405-setting-a-default-value-for-a-column/#findComment-1106691 Share on other sites More sharing options...
Jim R Posted September 3, 2010 Author Share Posted September 3, 2010 Additionally, I'm not inserting. I'm typing directly into my database, via SQLyog--a great tool. I was hoping I could set a default value for a column based on the variable output of two other columns. You're saying that is not the case? Link to comment https://forums.phpfreaks.com/topic/212405-setting-a-default-value-for-a-column/#findComment-1106692 Share on other sites More sharing options...
trq Posted September 3, 2010 Share Posted September 3, 2010 I was hoping I could set a default value for a column based on the variable output of two other columns. You're saying that is not the case? Yeah, i don't think its possible. Link to comment https://forums.phpfreaks.com/topic/212405-setting-a-default-value-for-a-column/#findComment-1106697 Share on other sites More sharing options...
Jim R Posted September 3, 2010 Author Share Posted September 3, 2010 It should be. Such a simple spreadsheet function, it would be nice to apply that type of setting. Link to comment https://forums.phpfreaks.com/topic/212405-setting-a-default-value-for-a-column/#findComment-1106699 Share on other sites More sharing options...
trq Posted September 3, 2010 Share Posted September 3, 2010 You could write a trigger that accomplishes the same I guess. Link to comment https://forums.phpfreaks.com/topic/212405-setting-a-default-value-for-a-column/#findComment-1106703 Share on other sites More sharing options...
Jim R Posted September 3, 2010 Author Share Posted September 3, 2010 YES...that's where I was going with my request. I'm just up with all (or much) terminology. If it was a spread sheet, I'd have =[column A]-[column B] (I need the hash in between) Is it simple like that, or should I just start digging around? Link to comment https://forums.phpfreaks.com/topic/212405-setting-a-default-value-for-a-column/#findComment-1106704 Share on other sites More sharing options...
fenway Posted September 7, 2010 Share Posted September 7, 2010 Of course, if you're just formatting for output, don't ever store this. Link to comment https://forums.phpfreaks.com/topic/212405-setting-a-default-value-for-a-column/#findComment-1108056 Share on other sites More sharing options...
Jim R Posted September 7, 2010 Author Share Posted September 7, 2010 Not sure what you mean by that. I just need to have that slug value so WP can match it. Link to comment https://forums.phpfreaks.com/topic/212405-setting-a-default-value-for-a-column/#findComment-1108058 Share on other sites More sharing options...
fenway Posted September 10, 2010 Share Posted September 10, 2010 Not sure what you mean by that. I just need to have that slug value so WP can match it. What's a slug value? Link to comment https://forums.phpfreaks.com/topic/212405-setting-a-default-value-for-a-column/#findComment-1109658 Share on other sites More sharing options...
Jim R Posted September 10, 2010 Author Share Posted September 10, 2010 It's ultimately what WordPress uses to create their permalinks. Link to comment https://forums.phpfreaks.com/topic/212405-setting-a-default-value-for-a-column/#findComment-1109678 Share on other sites More sharing options...
mikosiko Posted September 10, 2010 Share Posted September 10, 2010 to answer your original question... No.. is not possible. If you need to create/store your column C with A+B (concatenate) you must use triggers (2 .. 1 for Insert and 1 for update) as thorpe suggested. Link to comment https://forums.phpfreaks.com/topic/212405-setting-a-default-value-for-a-column/#findComment-1109688 Share on other sites More sharing options...
Jim R Posted September 10, 2010 Author Share Posted September 10, 2010 I'm just not familiar at all at how triggers work. Link to comment https://forums.phpfreaks.com/topic/212405-setting-a-default-value-for-a-column/#findComment-1109700 Share on other sites More sharing options...
mikosiko Posted September 10, 2010 Share Posted September 10, 2010 I'm just not familiar at all at how triggers work. time to read a bit then http://www.rustyrazorblade.com/2006/09/mysql-triggers-tutorial/ and http://dev.mysql.com/doc/refman/5.0/en/create-trigger.html Link to comment https://forums.phpfreaks.com/topic/212405-setting-a-default-value-for-a-column/#findComment-1109705 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.