您能否请一看这段代码,让我知道为什么我无法更新$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)。
由于
答案 0 :(得分:1)
您的UPDATE
查询语法错误,您不需要SET
所有列。它应该是
$query3= " UPDATE `charts_ecolo_yes`
SET `econo_sum_projects` = some_value,
`econo_sum_powerline` = some_other_value,