D
D
Danny132020-04-27 13:28:34
PHP
Danny13, 2020-04-27 13:28:34

How to display counted number of all tasks from sql table in given code?

Good afternoon, ladies and gentlemen!
Currently doing UX Design for one project but using PHP CRUD to better showcase interactive site layouts. Please help with PHP code, I don't know how to display the number of all tasks from the tasks table. In this code, it only displays the number of issues that have the status "under development", but I have three more columns of issues with other statuses that it doesn't show. I looked at a couple of examples on the Internet, but after tormenting myself with SELECT COUNT * from tasks, I did not achieve anything ...

<?php
    $pdo = Database::connect();
    /*Пробовал SELECT COUNT * from tasks но ничего не вышло, пробовал ещё просто все  значения всех столбец в ряд 
    написать: when workstatus="в разработке" and "готово" and "ждёт подтверждения" then 1 else null  - но тогда он 
    вообще ничего не показывает*/                                                               
    $sql2 = 'SELECT COUNT(case when workstatus = "В разработке" then 1 else null  end) as TaskCount FROM tasks';
    $total = 0;
    foreach ($pdo->query($sql2) as $row) {
    echo "<h5 class='mb-0 white-text'>" . $row['TaskCount'] . ' '. "</h5>";
    }
    Database::disconnect();
?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Daria Motorina, 2020-04-27
@Danny13

Select count(id) as TaskCount from tasks where workstatus in ("status1", "status2"," status3")
Example statuses, your actual statuses are needed there.
If all-all statuses are needed there, then simply select count (id) as TaskCount from tasks

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question