I want to put the value of count
into a variable and display it on the page.
here's my code:
<?php
try {
$pdo = new PDO('Database info');
} catch (PDOException $e) {
exit('Database error.');
}
$query = $pdo->prepare("select count from counter where count_id=1");
$query->execute();
return $query;
echo $query;
?>
This isn't working... any suggestions on how i should change this to get the count to display in a variable?
Thanks.
Change to:
$query = $pdo->prepare("select count(*) from counter where count_id=1");
$query->execute();
$count = $query->fetchColumn();
echo $count;
Modify the query as follows
$count = $con->query("SELECT COUNT(*) as num from counter where count_id=1")
->fetch(PDO::FETCH_ASSOC);
echo $count['num'];