获取个人资料视图的总视图?

时间:2016-08-10 09:42:34

标签: php mysql pdo

所以我有这个表包含:用户名,查看器,视图。我有两列:enter image description here

现在我所做的是一个称为:

的功能
public function TotalView($username)
        {
    $sql = "SELECT views from profile_views where username=:username";
    $stmt = $this->con->prepare($sql);
    $paramaters = [':username' => $username];
    $stmt->execute($paramaters);
    $count = $stmt->columnCount();
    return $count;

}

现在它在个人资料页面中显示了Views:1。我有什么不对的吗? 编辑:用户saty修复了它。我应该使用$ count = $ stmt-> rowCount();. 而不是columnCount();

1 个答案:

答案 0 :(得分:1)

columnCount()

  

返回结果集中的列数

反而使用

rowCount()

  

返回受上一个SQL语句影响的行数

<div class="color-picker">
<div class="well">
<button>Click here to pick a color</button>
Value: 
<input />
</div>

<div class="well">
<button>Click here to pick a color</button>
Value: 
<input />
</div>

<div class="well">
<button>Click here to pick a color</button>
Value: 
<input />
</div>

<div class="well">
<button>Click here to pick a color</button>
Value: 
<input />
</div>

<div class="well">
<button>Click here to pick a color</button>
Value: 
<input />
</div>
</div>

<div class="right-block">
</div>

OR

您可以使用

$stmt->execute($paramaters);
$count = $stmt->rowCount();