无法添加两个mysql列并返回合计 [英] Trouble adding two mysql columns and returning total

查看:87
本文介绍了无法添加两个mysql列并返回合计的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试添加mysql列,然后将这些列的总数返回到php页面.我让代码正常工作,但没有返回值:

I am attempting to add mysql columns and then return the total of the columns to a php page. I got the code to work but it is not returning the value:

<?
$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.

There is no features, contributions, likes in your condition. Also you are giving wrong name as parameter 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>';
?>

这篇关于无法添加两个mysql列并返回合计的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆