下面是我的脚本导入数据到mysql:
foreach ($file_data as $row) {
$sku = $row[$_POST["sku"]];
$title = $row[$_POST["title"]];
$slug = $row[$_POST["title"]];
$product_type = "physical";
$description = $row[$_POST["description"]];
}
if(isset($sku))
{
$query = "
INSERT INTO products
(sku, slug, product_type)
VALUES ".implode(",", $sku).",".implode(",", $slug).",".implode(",", $product_type)."
";
$statement = $connect->prepare($query);
if($statement->execute())
{
echo 'Data Imported Successfully';
}
}
现在有人能帮我把$title
和$description
加载到第二个表product_details
吗?
@更新@梅尔沃兹
foreach ($file_data as $row) {
$sku = $row[$_POST["sku"]];
$title = $row[$_POST["title"]];
$slug = $row[$_POST["slug"]];
$product_type = "physical";
$description = $row[$_POST["description"]];
if (isset($sku)) {
$statement = $connect->prepare("INSERT INTO products
(sku, slug, product_type)
VALUES '$sku','$slug','$product_type'");
$statement2 = $connect->prepare("INSERT INTO product_details
(title, description)
VALUES '$title','$description'");
if (!$statement->execute()) {
$error = 'None or part of the data was updated';
}
}
}
echo $error ?? 'Data Updated Successfully';
2条答案
按热度按时间7d7tgy0s1#
也许你可以推任何数组
gdrx4gfi2#
这可能对你有用。