如何在新表中插入行?

彼得拉斯·维克利斯(Petras Vilkelis)

我有一个价格解析器。我有一张新鲜的桌子。它从网站上获取价格,并生成可以在phpmyadmin上轻松运行的SQL文件。而且由于它会更新价格,所以制作不正确,但是我需要插入价格。

代码:

<?php 
$prices = json_decode(file_get_contents("https://api.csgofast.com/price/all"),true);
echo "we are get ".count($prices)." actual prices\r'n";

$sql = "";
foreach($prices as $k=>$v){
    $sql .="UPDATE analyst SET current_price=\"".$v."\" WHERE market_name=\"".$k."\";";
}

file_put_contents("prices_".time().".sql", $sql, FILE_APPEND | LOCK_EX);
echo "good job\r\n";
?>

它基本上是从网站上获取价格,并analyst使用信息更新我的表格。我所需要做的就是插入它们,而不更新它们。

我如何更改它,以使它生成一个SQL文件来插入它们而不是UPDATE?

希卡罗

您可以将代码更改为:

<?php 

$prices = json_decode(file_get_contents("https://api.csgofast.com/price/all"),true);
echo "we are get ".count($prices)." actual prices\r'n";

$sql = "";
foreach($prices as $k=>$v){
    $sql .="INSERT INTO analyst (current_price, market_name) VALUES (\"".$v."\", \"".$k."\");";
}

file_put_contents("prices_".time().".sql", $sql, FILE_APPEND | LOCK_EX);
echo "good job\r\n";


?>

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章