gpt4 book ai didi

php - 如何使用 PDO 获取列的总和?

转载 作者:行者123 更新时间:2023-11-30 23:07:12 25 4
gpt4 key购买 nike

php 说它不能转换成 int:

注意:C:\xampp\htdocs\elearning\pages\student\upload.php 中第 76 行的类 PDOStatement 的对象无法转换为 int:

              $userLoggedIn = $_SESSION['username'];

$stmt = $conn->prepare( "SELECT s.grade_level, s.section
FROM tblusers as u
JOIN tblstudents as s
ON u.username = s.username
WHERE u.username = :username" );
$stmt->execute(array( ':username' => $userLoggedIn ));

$file = $_FILES['file']['name'];
$filesize = $_FILES['file']['size'];
$filepath = "../../assets/uploads/" . $file;

$filelimit = $conn->prepare("SELECT SUM(f.filesize)
FROM tblfiles AS f
JOIN tblstudents AS s
ON f.uploader = s.username
WHERE f.uploader = ':username'");
$filelimit->execute(array(':username'=>$userLoggedIn));

这是第 76 行:if($filelimit > 1048576)

最佳答案

我猜你在从 sum(f.filesize) 获取值时遇到了问题。

试着给它一个像这样的别名

  SELECT SUM(f.filesize) as filesize

然后通过这个filesize

获取总和

关于php - 如何使用 PDO 获取列的总和?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21350464/

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