我正在尝试从一个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'");
}
由于
答案 0 :(得分:4)
只需使用一个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';
不要让where
复制整个表格。
更容易复制表格:
create table livetrack11 as select * from livetrack;