我正试图从表中获得薪水总和。我只需要回报总薪水。我试过了,
SELECT SUM(SalaryCol) FROM my_table;
如何在php中将查询结果作为变量?
答案 0 :(得分:2)
SELECT SUM(SalaryCol) as total_salary FROM my_table;
答案 1 :(得分:0)
$sql = 'SELECT SUM(SalaryCol) as total_salary FROM my_table';
//$con is your connection variable
$result=mysqli_query($con,$sql);
while($row=mysqli_fetch_array($result,MYSQLI_NUM)){
$salaries[] = $row['total_salary'];
}
return $salaries;
然后您可以将其作为数组访问并执行任何操作
答案 2 :(得分:0)
好的,我自己想通了。
$query = "SELECT SUM(SalaryCol) FROM my_table";
$sum = mysqli_fetch_row(mysqli_query($con, $query));
echo "Total : ".$sum[0];