ok...since my last question was obviously too hard, so here's a better one...
I know how to select data from a table, and I know how to loop it using a while statement for display purposes.
So my question is this, I want to select all data from one table and insert it into another without displaying it at all. How can this be accomplished?
Here's some code to reflect on, but it only snags the first record:
$sql = "SELECT * FROM table1 ORDER BY id ASC";
$connection = mysql_connect($default->db_host, $default->db_user, $default->db_pass)
or die ("Couldn't connect to server.");
$db = mysql_select_db($default->db, $connection)
or die ("Couldn't select database.");
$sql_result = mysql_query($sql)
or die("Couldn't execute query.");
if (!$sql_result) {
echo "Could not snag content for migration! Contact the Administrator!";
} else {
if (mysql_num_rows ($sql_result) > 0 ) {
while ($row = mysql_fetch_array($sql_result)) {
$data1 = $row["data1"];
$data2 = $row["data2"];
$data3 = $row["data3"];
}
$sql = "INSERT INTO table2 VALUES ( NULL, '$data1', '$data2', '$data3')";
$connection = mysql_connect($default->db_host, $default->db_user, $default->db_pass)
or die ("Couldn't connect to server.");
$db = mysql_select_db($default->db, $connection)
or die ("Couldn't select database.");
$sql_result = mysql_query($sql)
or die("Couldn't execute query.");
if (!$sql_result) {
echo "Couldn't write to table! Please contact the administrator!";
} else {
echo "
<table width=$default->table_width border=\"0\" cellspacing=\"2\" cellpadding=\"2\" align=\"center\">
<tr align=\"left\">
<td>You have successfully migrated the data from the staging area to the live page.</td>
</tr>
</table>";