Having Trouble getting Data in to HTML Table
Posted: Tue Feb 13, 2007 8:07 am
feyd | Please use
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Hi I am trying to write a php page to query a database and make an HTML table.
The database is MS SQL.
When the page runs i get nothing.
Any help would be great.
Then i can try to lern some conditional formating!!!!!!Code: Select all
<?
require_once 'pear/pear/MDB2.php';
function show_feed() {
$dsn = 'mssql://mom:mom@zcgprmom01:1433/OnePoint';
$dbh = MDB2::connect($dsn);
$sql = "select cr.Name as groupName, sum(c.Alerts) As Alerts, sum(al.UnacknowledgedCount) as TotalUnacknowledgedCount,
t.MaxAlertLevel, t.NumberOfComputers
FROM dbo.fn_AllGroupsToComputers() d join ComputerRule cr on cr.idComputerRule = d.groupId JOIN
(select idComputer,
(SELECT COUNT(*)
FROM [dbo].[Event] E
WHERE (E.idGeneratedBy = C.idComputer)) AS Events,
(select COUNT(*)
FROM [dbo].[Alert] A
WHERE (A.idComputer = C.idComputer AND ResolutionState < 255)) AS Alerts--,
--I.State AS HighestOpenAlertState
FROM dbo.Computer C WITH (NOLOCK) ) c --JOIN [dbo].[Instance] I WITH (NOLOCK) ON I.InstanceID = C.idComputer
on c.idComputer = d.ComputerId
join
(select MaxAlertLevel=Max( MaxAlertLevel),ComputerGroupName,
NumberOfComputers=SUM( ComputerCount)
from ComputerGroupViewStep1
group BY ComputerGroupName)t
ON t.ComputerGroupName = cr.[Name]
Left outer join AlertUnresolvedStatisticsView al on al.idComputer = c.idComputer
Where cr.Name in ('2000 Servers','2003 Servers','Active Directory','Back-Up Service','Citrix Service','DHCP Servers',
'DNS Server','Domain Controllers','DR Servers','Exchange Service','File Server Cluster','Motability On-Line','Print Service',
'SQL Servers')
group by cr.Name, t.MaxAlertLevel, t.NumberOfComputers";
$sth = $dbh->query($sql);}
// start table and display headers
print("<tr>");
print("<td>$row[0]</td>");
print("<td>$row[1]</td>");
print("<td>$row[2]</td>");
print("<td>$row[3]</td>");
print("<td>$row[4]</td>");
print("</tr>");
// work through the request result
while($sth->fetchInto($row)) {
display_row($row);
}
print "</table>";
}
// display a single row in the table
function display_row($row) {
// result columns are referenced by index - give them meaningful names
$groupName = 0;
$Alerts = 1;
$TotalUnacknowledgedCount = 2;
$MaxAlertLevel = 3;
$NumberOfComputers = 4;
print "<tr>";
print "<td>".$row[$groupName]."</td>";
print "<td>".$row[$Alerts]."</td>";
print "<td>".$row[$TotalUnacknowledgedCount]."</td>";
print "<td>".$row[$MaxAlertLevel]."</td>";
print "<td>".$row[$NumberOfComputers]."</td>";
print "</tr>n";
}
?>feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]