我需要能够将所有没有userid的行复制到具有等于1的userid的同一个表中。这是我拥有的代码:(当我运行它时它不工作),它确实使用echo显示了items字段和widget id字段。但是它不插入数据。有什么建议吗
$sql=("SELECT * from options WHERE userid='' ");
$resultat= mysql_query($sql);
while($row = mysql_fetch_array($resultat))
{
$userid="1";
echo $items.$widgetid."<br>";
$widgetid = $row['widgetid'];
$items = $row['items'];
$stats = $row['stats'];
$upd=("INSERT INTO options (userid, widgetid, items,stats)
VALUES ('$userid', '$widgetid','$items', '$stats')");
mysql_query($upd);
}发布于 2012-03-01 19:01:13
INSERT INTO options
SELECT '1' AS userid, widgetid, items, stats
FROM options
WHERE userid = ''假设这是表中声明的列的顺序。
发布于 2012-03-01 18:42:39
我认为您只需要更新userid='‘的行
update options
set userid=1
where userid='';
$upd=("INSERT INTO options (userid, widgetid, items,stats)
select 1, widgetid, stats from options
where userid='' ");发布于 2012-03-01 18:46:53
create table newTable like oldTable;
insert into newTable
select * from oldTable
where userid = '';但也许你真的只需要像纳温说的那样更新一下?
https://stackoverflow.com/questions/9514658
复制相似问题