gpt4 book ai didi

php - 在 MySQL 中插入一个变量,该变量随每一行而变化

转载 作者:太空宇宙 更新时间:2023-11-03 12:29:18 24 4
gpt4 key购买 nike

    while ($row = mysql_fetch_array($sqlquery)) 
{

$fd = strtotime($row['date1']);
$sd = strtotime($row['date2']);


$dates = floor(($sd - $fd ) / 86400);

$price = $dates * 25;
}

我想将每行的 $price 插入到另一个表中。我无法通过单个插入来执行此操作,因为每次 $price 都不同。

最佳答案

"INSERT INTO `yourtable` ('price') VALUES ('".$price."')";

将它放在 while 循环中,所以

while ($row = mysql_fetch_array($sqlquery)) 
{

$fd = strtotime($row['date1']);
$sd = strtotime($row['date2']);


$dates = floor(($sd - $fd ) / 86400);

$price = $dates * 25;
"INSERT INTO `yourtable` ('price') VALUES ('".$price."')";
}

这意味着 while 循环的每次迭代都会有一个插入,每次 $price 都不同。

关于php - 在 MySQL 中插入一个变量,该变量随每一行而变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16220287/

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