ITStudent Posted February 13, 2006 Share Posted February 13, 2006 Is it possible to insert the values of an array into a table, with each value being stored in a new row.I need to take the value of the array select information from a table based on this and then insert to the second table.Thanks. Quote Link to comment Share on other sites More sharing options...
obsidian Posted February 13, 2006 Share Posted February 13, 2006 [!--quoteo(post=345456:date=Feb 13 2006, 02:43 PM:name=ITStudent)--][div class=\'quotetop\']QUOTE(ITStudent @ Feb 13 2006, 02:43 PM) [snapback]345456[/snapback][/div][div class=\'quotemain\'][!--quotec--]Is it possible to insert the values of an array into a table, with each value being stored in a new row.I need to take the value of the array select information from a table based on this and then insert to the second table.Thanks.[/quote]i'm not sure i follow what you're asking. the simple answer to your question is yes, you can store each value in an array in a new row. something like this is all you need:[code]<?php$q = "INSERT INTO tableName (colName) VALUES ";foreach ($array as $value) $q .= "('$value'), ";$q = substr($q, 0, strlen($q) - 2);mysql_query($q);?>[/code] Quote Link to comment Share on other sites More sharing options...
wickning1 Posted February 14, 2006 Share Posted February 14, 2006 You can do it all in MySQL with the INSERT INTO SELECT syntax. It should look something like this:INSERT INTO secondtable (col1, col2, col3)SELECT col1, col2, col3 FROM firsttable WHERE thepopeiscatholic=1 Quote Link to comment 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.