获取PDO WHERE中的结果

时间:2013-07-24 23:49:54

标签: php mysql pdo count

我正在尝试获取用户ID =会话ID的数字。例如,如果用户ID = 1,我想获取用户拥有的投注金额。

我尝试使用MySQL的COUNT但它没有给出正确的结果。我做错了什么?

![] [1] http://puu.sh/3KYVf.png

<?php
include_once('db.php');
session_start();

    $selectTotalBets = $db->prepare("SELECT COUNT(*) FROM `users` WHERE `uid` = :uid");

        $selectTotalBets->execute(array(':uid' => $_SESSION['uid']));

            $TotalBetsRow = $selectTotalBets->fetch();

                $userTotalBets = $TotalBetsRow['uid'];



?>

2 个答案:

答案 0 :(得分:0)

include_once( 'db.php中'); 在session_start();

$selectTotalBets = $db->prepare("SELECT MAX(bid) AS `totalBets` FROM `users` WHERE `uid` = :uid");

    $selectTotalBets->execute(array(':uid' => $_SESSION['uid']));

        $TotalBetsRow = $selectTotalBets->fetch();

            $userTotalBets = $TotalBetsRow['totalBets'];

用户Max()获取最大值。

答案 1 :(得分:-1)

根据劳伦斯的建议 -

<?php
include_once('db.php');
session_start();

    $selectTotalBets = $db->prepare("SELECT COUNT(*) AS `totalBets` FROM `users` WHERE `uid` = :uid");

        $selectTotalBets->execute(array(':uid' => $_SESSION['uid']));

            $TotalBetsRow = $selectTotalBets->fetch();

                $userTotalBets = $TotalBetsRow['totalBets'];

?>