Jump to content

Archived

This topic is now archived and is closed to further replies.

ITStudent

Inserting array values in table

Recommended Posts

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.

Share this post


Link to post
Share on other sites
[!--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]

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

×

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.