How to write this query in PDO for and get all the three output in three different arrays [closed]

StackOverflow https://stackoverflow.com/questions/22984476

  •  01-07-2023
  •  | 
  •  

Question

I have this sql query

SELECT COUNT( testRunID ) , platform, SUM( IF( STATUS = 'passed', 1, 0 ) ) passed_count, 
SUM( IF( STATUS = 'failed', 1, 0 ) ) failed_count, 
SUM( IF( STATUS = 'incomplete', 1, 0 ) ) incomplete_count
FROM tooldata
GROUP BY platform
ORDER BY platform

which I having trouble writing in pdo. And how I can have the output incomplete_count, failed_count, passed_count in three different arrays ? Guys pls help me. I am very new to php and pdo.

Was it helpful?

Solution

I should not be answering this but seeing so many duplicates I should give you the answer so that you won't be posting anymore - Do like this -

$status = 'failed';
$allTest = $conn->prepare('SELECT SUM( IF( STATUS = :status, 1, 0 ) ) passed_count FROM tooldata GROUP BY platform ORDER BY platform' );
$allTest->execute(array(':status' => $status));

and then repeat the same query for - $status = 'passed'; $status = 'incomplete';

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top