MySQL数据库怎样把一个表的数据插入到另一个表
1个回答
展开全部
代码如下:
<?php
header("Content-type:text/html;charset=utf-8");
$conn = mysql_connect("localhost","root","");
mysql_select_db('nnd',$conn);
mysql_select_db('ahjk',$conn);
mysql_query("set names utf8");
$sql = mysql_query("select content,partid from phpcms_c_disease order by contentid desc limit
//我这里是查询出表的数据 然后循环插入
$sql1= "INSERT INTO `nnd`.`demo`(content,parid) VALUES";
while($row = mysql_fetch_assoc($sql)){
$sql1.="('$row[content]','$row[partid]'),";
}
$sql1.=")";
$sql2 .= str_replace(",)",";",$sql1);
mysql_query($sql2);
?>
<?php
header("Content-type:text/html;charset=utf-8");
$conn = mysql_connect("localhost","root","");
mysql_select_db('nnd',$conn);
mysql_select_db('ahjk',$conn);
mysql_query("set names utf8");
$sql = mysql_query("select content,partid from phpcms_c_disease order by contentid desc limit
//我这里是查询出表的数据 然后循环插入
$sql1= "INSERT INTO `nnd`.`demo`(content,parid) VALUES";
while($row = mysql_fetch_assoc($sql)){
$sql1.="('$row[content]','$row[partid]'),";
}
$sql1.=")";
$sql2 .= str_replace(",)",";",$sql1);
mysql_query($sql2);
?>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询