I am trying to obtain the number of determinated task types, but it gives me error: Trying to get property of non-object
$statement = $pdo->prepare("SELECT COUNT(DISTINCT Company_Name)
FROM salesplus WHERE `Task_Type` = 'Form Sent'
AND `Consultant_name` = 'Name Surname'");
$statement->execute();
$result=$statement->fetch(PDO::FETCH_OBJ);
foreach($result as $row){
echo $row->Task_Type;
Thank you a lot!
That's not how it works... try (to get count of exact task):
SELECT COUNT(*) as count FROM (SELECT DISTINCT Company_Name FROM salesplus WHERE `Task_Type` = 'Form Sent' AND `Consultant_name` = 'Name Surname') as s
Or better (get list of companies and count of selected tasks for each company):
SELECT `Company_Name`,count(*) as count FROM salesplus WHERE `Task_Type` = 'Form Sent' AND `Consultant_name` = 'Name Surname' GROUP BY `Company_Name`
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.