theprogrammer theprogrammer - 1 year ago 52
MySQL Question

get total view of profile views?

so i have this table which contains: username,viewer,views. and i have two columns which is: enter image description here

now what i did is a function known as :

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


now it says Views:1 in the profile page. is there anything i'm doing wrong?
EDIT: user saty has fixed it. i should of used $count = $stmt->rowCount();.
instead of columnCount();

Answer Source


Returns the number of columns in the result set

SO instead use


Returns the number of rows affected by the last SQL statement

$count = $stmt->rowCount();


You can use

$rows = $stmt->fetchAll();
$count = count($rows);
return $count;