I am trying to combine three select statements from the same table in order to use the results to complete a . The code am currently using returns:
Resource id #3 Resource id #4 Resource id #5
I have done some research on UNION or JOIN, but I haven't found anything that works. Here is my current approach:
$statecount = pg_query($conn, "
SELECT
COUNT (*) as totalst
FROM
fpscdb001_ws_001.incident
WHERE
incident.initial_symptom = 'Chrome Install' AND
incident.state_1 = 'MA';");
$sched = pg_query($conn, "
SELECT
COUNT (*) as totalsch
FROM
fpscdb001_ws_001.incident
WHERE
incident.initial_symptom = 'Chrome Install' AND
incident.state_1 = 'MA' AND
incident.status_1 = 'Scheduled';");
$closed = pg_query($conn, "
SELECT
COUNT (*) as totaldone
FROM
fpscdb001_ws_001.incident
WHERE
incident.initial_symptom = 'Chrome Install' AND
incident.state_1 = 'MA' AND
incident.status_1 = 'Closed';");
if (!$statecount) {
echo "Query failed on state count.
";
exit;
}
if (!$sched) {
echo "Query failed on sched.
";
exit;
}
if (!$closed) {
echo "Query failed on closed.
";
exit;
}
{
echo "<td> $statecount </td>";
echo "<td> $sched </td>";
echo "<td> $closed </td>";
}
pg_close($conn);
Through some trial and error I was able to make it work...
$statecount = pg_query($conn, "
SELECT
COUNT (*) as totalst
FROM
fpscdb001_ws_001.incident
WHERE
incident.initial_symptom = 'Chrome Upgrade' AND
incident.state_1 = 'AR' AND
incident.status_1 != 'Closed'
UNION ALL
SELECT
COUNT (*) as totalsch
FROM
fpscdb001_ws_001.incident
WHERE
incident.initial_symptom = 'Chrome Upgrade' AND
incident.state_1 = 'AR' AND
incident.staging = 'True' AND
incident.is_installed != 'True' AND
incident.status_1 != 'Closed'
UNION ALL
SELECT
COUNT (*) as totaldone
FROM
fpscdb001_ws_001.incident
WHERE
incident.initial_symptom = 'Chrome Upgrade' AND
incident.state_1 = 'AR' AND
incident.staging = 'True' AND
incident.is_installed = 'True';");
if (!$statecount) {
echo "Query failed on state count.
";
exit;
}
while ($counts = pg_fetch_row($statecount)){
echo "<td>$counts[0]</td>";
}