PCHomepage
Programmer
I'm rusty at this and, although it's related to MSSQL, I think the answer is PHP. I HAD a query that was simply bringing up a single column of values but I just reworked it to be more dynamic and I am not sure who to present the results. Since the names and values each have their own CSS styles, I need two separate columns which was easy when one was hard-coded but now that it's not, I'm stuck. Can anyone help? Here is what I have (it's inside a function, by the way):
Code:
$tsql = "Declare @_tbl table(
Condition varchar(50),
Value decimal(10,0));
DECLARE @YearVal varchar(30);
SET @YearVal = 2010;
INSERT INTO @_tbl Select 'Infectious Disease', SUM([INFECT-DISEASE]) FROM [Section 3-5] WHERE [Section 3-5].OSHPD_ID IN (SELECT OSHPD_ID FROM PARTNER_CLINICS) AND REPT_YEAR = @YearVal
INSERT INTO @_tbl Select 'Neoplasms', SUM(NEOPLSMS) FROM [Section 3-5] WHERE [Section 3-5].OSHPD_ID IN (SELECT OSHPD_ID FROM PARTNER_CLINICS) AND REPT_YEAR = @YearVal
INSERT INTO @_tbl Select 'Endocrine', SUM(ENDOCRN) FROM [Section 3-5] WHERE [Section 3-5].OSHPD_ID IN (SELECT OSHPD_ID FROM PARTNER_CLINICS) AND REPT_YEAR = @YearVal
INSERT INTO @_tbl Select 'Blood Disease', SUM(BLOOD_DIS) FROM [Section 3-5] WHERE [Section 3-5].OSHPD_ID IN (SELECT OSHPD_ID FROM PARTNER_CLINICS) AND REPT_YEAR = @YearVal
INSERT INTO @_tbl Select 'Mental Disorders', SUM(MENTAL) FROM [Section 3-5] WHERE [Section 3-5].OSHPD_ID IN (SELECT OSHPD_ID FROM PARTNER_CLINICS) AND REPT_YEAR = @YearVal
INSERT INTO @_tbl Select 'Nervous System', SUM(NERVIOUS) FROM [Section 3-5] WHERE [Section 3-5].OSHPD_ID IN (SELECT OSHPD_ID FROM PARTNER_CLINICS) AND REPT_YEAR = @YearVal
SELECT TOP 5 Condition, Value FROM @_tbl ORDER BY Value Desc";
// Execute query.
$stmt = sqlsrv_query($conn, $tsql);
// Present results
$row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_NUMERIC);
$Values = "\n\n<div class=\"DiagnosisTitle\">Top 5 Encounters by Diagnosis</div>\n\n".
"<div class=\"DiagColumn1\">Endocrine<br>\n".
"Circulatory<br>\n".
"Respiratory<br>\n".
"Child Preventative Services<br>\n".
"Nervous System</div>\n\n".
"<div class=\"DiagColumn2\">".
"<span class=\"RightAlign\">".number_format($row[0])."</span><br>\n".
"<span class=\"RightAlign\">".number_format($row[1])."</span><br>\n".
"<span class=\"RightAlign\">".number_format($row[2])."</span><br>\n".
"<span class=\"RightAlign\">".number_format($row[3])."</span><br>\n".
"<span class=\"RightAlign\">".number_format($row[4])."</span>\n".
"</div>\n\n";
return $Values;