您能否看一下这段代码,让我知道为什么我无法更新$query3上的临时表

$query = "CREATE TEMPORARY TABLE IF NOT EXISTS `charts_ecolo_yes` (


           SET `econo_sum_projects` = (SELECT COUNT(`project`) FROM `ecolo-cu-yes`  WHERE c_1000=1 ),
       SET `econo_sum_powerline` = (SELECT SUM(`powerline_length`) FROM `ecolo-cu-yes`  WHERE c_1000=1 ),
       SET `econo_sum_roads` = (SELECT SUM(`road_length`) FROM `ecolo-cu-yes`  WHERE c_1000=1 ),
       SET `econo_sum_cost` = (SELECT SUM(`cost_per_year`) FROM `ecolo-cu-yes`  WHERE c_1000=1 ),
       SET `econo_sum_penstlock` = (SELECT SUM(`penstlock` FROM `ecolo-cu-yes`  WHERE c_1000=1 )
        ";
$con->query($query3);
$query4 = "SELECT *  FROM `charts_ecolo_yes`" ;
$results = $con->query($query4);
if ($results) {
    $row = $results->fetch_array(MYSQLI_NUM);
    $row = array_map('floatval', $row); // Convert strings to numbers
    echo json_encode($row);
}


Here是示例结果页面,即使运行$con->query($query3);后您也可以看到它,但我仍在最后5列获得默认值(100)。

谢谢

最佳答案

您的UPDATE查询语法错误,不需要所有列都使用SET。它应该是

$query3= " UPDATE `charts_ecolo_yes`
SET `econo_sum_projects` = some_value,
`econo_sum_powerline` = some_other_value,

09-09 20:26