我正在尝试添加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>
答案 0 :(得分:1)
您的情况中没有features
,contributions
,likes
。您也将错误的名称作为参数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>';
?>