我正在尝试添加 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>
最佳答案
您的情况没有功能
、贡献
、点赞
。此外,您还提供了错误的名称作为参数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/28182965/