Having Trouble getting Data in to HTML Table

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
DarkNastee
Forum Newbie
Posts: 3
Joined: Tue Feb 13, 2007 7:59 am

Having Trouble getting Data in to HTML Table

Post by DarkNastee »

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]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

The code posted thus far does not run the function show_feed().
DarkNastee
Forum Newbie
Posts: 3
Joined: Tue Feb 13, 2007 7:59 am

When i call the function

Post by DarkNastee »

Thanks for your reply i call the function with a ?action=showfeed.

As I still lerning PHP any advice would be helpfull.
Maybe even stop using the function this way or any suggestion as i am stuck.
Thanks for the reaply FEYD
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Unless the code you are using understands what "action=showfeed" in the URL means, nothing will happen.

$_GET will have the information generated from the URL. You will need an if() or possibly a switch statement to run the proper code given the correct settings from the $_GET data.
DarkNastee
Forum Newbie
Posts: 3
Joined: Tue Feb 13, 2007 7:59 am

ok so i removed the function

Post by DarkNastee »

Hi thanks for you repy.

i removed the function to test the page but now get a blank page.

Is my code correct once i have removed the referance to the show feed function?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

You probably have a parse error or something similar. Look through your error logs and/or turn on display_errors (and set error_reporting to E_ALL)
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

This was the code in your function. It returns nothing, does nothing and processes nothing that is available outside the scope of the function:

Code: Select all

<?php
$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);
?>
You need to get the $sth value from the function. You might want to look in to the return keyword.
Post Reply