RJP1 Posted February 3, 2011 Share Posted February 3, 2011 Hi guys, What's the best way to iterate though a table similar to this: ID | Introtext | Fulltext ... and add the fulltext data onto the end of the intro text data? Basically combining the intro and full text into one column? Can I do this in PHP? E.g. ID | Introtext | Fulltext -------------------------------------------------- 1 | <p>intro</p> | <p>main text</p> and turn that into ID | Introtext | Fulltext ----------------------------------------------------------------------- 1 | <p>intro</p><p>main text</p> | <p>main text</p> Thanks guys! RJP1 Quote Link to comment https://forums.phpfreaks.com/topic/226623-merging-2-columns-into-1/ Share on other sites More sharing options...
Pikachu2000 Posted February 3, 2011 Share Posted February 3, 2011 This query will run through every record in the table, so if you don't need it to do that, don't run it . . . UPDATE `table` SET `Introtext` = CONCAT(`Introtext`, `Fulltext`) Quote Link to comment https://forums.phpfreaks.com/topic/226623-merging-2-columns-into-1/#findComment-1169639 Share on other sites More sharing options...
RJP1 Posted February 3, 2011 Author Share Posted February 3, 2011 Thanks for the help. Does this keep the fulltext column as it is? It doesn't delete it or anything? RJP1 Quote Link to comment https://forums.phpfreaks.com/topic/226623-merging-2-columns-into-1/#findComment-1169642 Share on other sites More sharing options...
Pikachu2000 Posted February 4, 2011 Share Posted February 4, 2011 Nope. It will remain. I have to wonder why you're doing this though. There's nearly never a good reason to duplicate data like that. Quote Link to comment https://forums.phpfreaks.com/topic/226623-merging-2-columns-into-1/#findComment-1169649 Share on other sites More sharing options...
RJP1 Posted February 4, 2011 Author Share Posted February 4, 2011 There's a very good reason. It's for user interface simplicity. Basically, my system has 2 text boxes for users to write in to add listings to my site. All this text is then output on their page. The add/edit page therefore has 2 boxes and it's just an extra input box for the sake of it, especially as I don't use the intro text for any other special reason. I may as well just have one box. But to save me from having to copy and paste everyones 2 boxes worth of data into the intro box i just wondered if there was a quicker MySQL way. And you helped me out a treat. I just need to backup and try it out later. Thanks again, RJP1 Quote Link to comment https://forums.phpfreaks.com/topic/226623-merging-2-columns-into-1/#findComment-1169662 Share on other sites More sharing options...
awjudd Posted February 4, 2011 Share Posted February 4, 2011 Couldn't you just do it upon retrieval from the database (i.e. in your SELECT query?) ~judda Quote Link to comment https://forums.phpfreaks.com/topic/226623-merging-2-columns-into-1/#findComment-1169667 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.