I am trying to take data from one mysql table and insert it in to another so i can make some updates without using a live db table. The problem i am having is it is taking the data out of the first table but not inserting it in the second. Any help would be appreciated.
我试图从一个mysql表中获取数据并将其插入到另一个mysql表中,这样我就可以在不使用实时数据库表的情况下进行一些更新。我遇到的问题是它是从第一个表中取出数据而不是在第二个表中插入数据。任何帮助,将不胜感激。
error_reporting(E_ALL);
ini_set("display_errors", 1);
$host="";
$username="";
$password="";
$database="";
mysql_connect($host,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query = "SELECT * FROM livetrack where member_id ='000826'";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)){
$ipa = $row['ip_address'];
$date = $row['date'];
$referer = $row['referer'];
$string = $row['string'];
$member_id = $row['member_id'];
echo "Insert Data.....";
mysql_query("INSERT INTO livetrack11 (ip_address, date, referer, string, member_id)
VALUES ('$ipa', '$date', '$referer', '$string', '$member_id'");
}
Thanks
1 个解决方案
#1
4
Just use a simgle insert-select
statement:
只需使用simgle insert-select语句:
insert into livetrack11 (ip_address, date, referer, string, member_id)
select ip_address, date, referer, string, member_id
from livetrack
where member_id ='000826';
Leave off the where
to simply copy the whole table.
不要在哪里简单地复制整个表格。
Even easier to copy the table:
更容易复制表格:
create table livetrack11 as select * from livetrack;
#1
4
Just use a simgle insert-select
statement:
只需使用simgle insert-select语句:
insert into livetrack11 (ip_address, date, referer, string, member_id)
select ip_address, date, referer, string, member_id
from livetrack
where member_id ='000826';
Leave off the where
to simply copy the whole table.
不要在哪里简单地复制整个表格。
Even easier to copy the table:
更容易复制表格:
create table livetrack11 as select * from livetrack;