gpt4 book ai didi

php - 不总结整列

转载 作者:行者123 更新时间:2023-11-29 04:07:48 24 4
gpt4 key购买 nike

因为它没有计算 first_paymentSUM 整列。 我试过“SELECT SUM(first_payment) FROM\Customer Information``,它作为未识别的索引 first_payment 返回。有什么原因吗?

    <?php
error_reporting(E_ALL);
ini_set("display_errors", 1);


$pay=$_REQUEST['payment'];

// MySQL database connection, username, password, database name
$con=mysqli_connect("localhost","user","pass","db_name");

// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

if ($pay=="first")
$query="SELECT *, SUM(first_payment) FROM `Customer Information`";
else if ($pay=="second")
$query="SELECT *, SUM(second_payment) FROM `Customer Information`";
else if ($pay=="third")
$query="SELECT *, SUM(third_payment) FROM `Customer Information`";
else if ($pay=="fourth")
$query="SELECT *, SUM(fourth_payment) FROM `Customer Information`";


$result = mysqli_query($con,$query);

// Executing and error checking of query
if (!mysqli_query($con,$query)) {
die('Error: ' . mysqli_error($con));
}


while ($row = mysqli_fetch_array($result)) {
switch($pay)
{
case "first":
echo $row['first_payment'];
break;
case "second":
echo $row['second_payment'];
break;
case "third":
echo $row['third_payment'];
break;
case "fourth":
echo $row['fourth_payment'];
break;
default:
echo "nothing selected";
}
}
mysqli_close($con);
?>

最佳答案

更改您的查询并为您在代码中使用的金额提供正确的别名。试试这个

if ($pay=="first") 
$query="SELECT *, SUM(first_payment) AS first_payment FROM `Customer Information`";
else if ($pay=="second")
$query="SELECT *, SUM(second_payment) AS second_payment FROM `Customer Information`";
else if ($pay=="third")
$query="SELECT *, SUM(third_payment) AS third_payment FROM `Customer Information`";
else if ($pay=="fourth")
$query="SELECT *, SUM(fourth_payment) AS fourth_payment FROM `Customer Information`";

关于php - 不总结整列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25050398/

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