在" table1"中更改值时遇到问题来自" table2"使用INSERT INTO SELECT声明。将table2复制到table1中。
让我解释一下......
你在下面的table2的SELECT语句中看到 AND group_name = 'djsfshj'
...我需要将该值(djsfshj)放入" table1"但是当我运行我的代码时,table1并没有添加任何东西。它有点忽略它,我没有错误。如果我删除AND group_name = 'djsfshj'
我的代码有效,但group_name将为空。
我在想我怎样才能让它发挥作用。知道为什么会这样吗?任何帮助表示赞赏!
代码:
foreach ($_GET["users_slideshows"] as $users_pick) {
$sql = "INSERT INTO table1 (username, volume, name, image, content, cssanimate, group_name)
SELECT '".$user_data['data']['username']."', volume, name, image, content, cssanimate, group_name
FROM table2 WHERE volume IN ('".$users_pick."') AND group_name = 'djsfshj' ";
if ($conn->query($sql) === TRUE) {
echo "";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
}
答案 0 :(得分:0)
尝试使用PHP's join将变量$_GET["users_slideshows"]
的内容设为逗号分隔值
$users_pick = join(',',$_GET["users_slideshows"]);
答案 1 :(得分:0)
我发现查询中的引文不准确,您可以尝试:
$sql = "INSERT INTO table1 (username, volume, name, image, content, cssanimate, group_name) ";
foreach ($_GET["users_slideshows"] as $users_pick) {
$sql .= "SELECT ".$user_data['data']['username'].", volume, name, image, content, cssanimate, group_name
FROM table2 WHERE volume IN ('".$users_pick."') AND group_name = 'djsfshj' ";
}
if ($conn->query($sql) === TRUE) {
echo "";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}