gpt4 book ai didi

php - 无法添加两个mysql列并返回合计

转载 作者:行者123 更新时间:2023-11-29 23:08:32 25 4
gpt4 key购买 nike

我试图添加mysql列,然后将这些列的总数返回到php页面。我有代码可以工作,但是没有返回值:

<?
$pointresults2 = $dbh->prepare("SELECT sum(features + contributions + likes
)
AS total FROM points WHERE (ID = :user_ID)");
$pointresults->bindParam(':user_ID', $user_ID, PDO::PARAM_INT);
$pointresults2->execute();
$pointrow2 = $pointresults2->fetchAll(PDO::FETCH_ASSOC);
?>

<h3><b>Points TEST: <?php echo $pointrow2[0]['total'] ?></b></h3>

最佳答案

您的状况中没有featurescontributionslikes。另外,您给错误的名称作为参数user_ID

<?php
$stmt = $dbh->prepare("SELECT sum(features + contributions + likes) AS total FROM points WHERE (ID = :user_ID)");
$stmt->bindParam(':user_ID', $user_ID, PDO::PARAM_INT);
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);

echo '<h3>'. $user_ID .' have '. $row['total'] .' Points.</h3>';
?>

关于php - 无法添加两个mysql列并返回合计,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28184302/

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