dongpu2727 2012-03-12 16:00
浏览 35
已采纳

从一个mysql表获取信息并将其插入另一个

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.

 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条回答 默认 最新

  • dsdioa9545 2012-03-12 16:02
    关注

    Just use a simgle insert-select statement:

    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;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 静电纺丝煅烧后如何得到柔性纤维
  • ¥15 (标签-react native|关键词-镜像源)
  • ¥100 照片生成3D人脸视频
  • ¥15 伪装视频时长问题修改MP4的时长问题,
  • ¥15 JETSON NANO
  • ¥15 VS开发qt时如何在paintgl函数中用pushbutton控制切换纹理
  • ¥20 关于 openpyxl 处理excel文件地问题
  • ¥15 MS中不知道高分子的构型怎么构建模型
  • ¥60 QQOP数据,什么是op数据号,怎么提取op数据!能不能大量提取(语言-c语言)
  • ¥15 matlab代码 关于微分方程和嵌套的分段函数。