gpt4 book ai didi

php - 将html表内容移动到sql数据库

转载 作者:行者123 更新时间:2023-11-29 13:34:50 26 4
gpt4 key购买 nike

我有一个表格(使用 php 从另一个网站抓取),但现在我想将其内容导入到我的数据库中(而不是仅仅打印出表格)。

这是使用以下代码从表中打印输出 ( http://i.stack.imgur.com/NnbAo.png ):

<?php
$uitvoer = getTable();
echo "<table">;
foreach ($uitvoer as $row) {
echo "<tr>";
foreach ($row as $col) {
echo "<td>" . $col . "</td>";
}
echo "</tr>";
}
echo"</table>";
?>

当我尝试这样做时,我的数据库没有任何反应:

<?php
$con = mysqli_connect("mysql1.000webhost.com","a2902119_lowavol","pswd")
$uitvoer = getTable();
foreach ($uitvoer as $row) {
foreach ($row as $col) {
$query += "'" . $col . "', ";
}
$sql="INSERT INTO test (cel1, cel2, cel3, cel4, cel5, cel6, cel7, cel8, cel9) VALUES ($query)";
mysqli_query($con, $sql);
}
?>

我对 PHP 知之甚少。谢谢你帮助我!

最佳答案

PHP 的连接运算符是 (.) 而不是 (+)

  <?php
$con = mysqli_connect("mysql1.000webhost.com","a2902119_lowavol","pswd")
$uitvoer = getTable();
foreach ($uitvoer as $row) {
$query = array();
$insert = "";
$insert_values = "";
foreach ($row as $col) {
$query[] = $col;
}
$insert_values = implode("','", $query) ;
$insert = "'".$insert_values."'";
$sql = "INSERT INTO test (cel1, cel2, cel3, cel4, cel5, cel6, cel7, cel8, cel9) VALUES ($insert)";
mysqli_query($con, $sql);
}
?>

关于php - 将html表内容移动到sql数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18889769/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com