Tim Tim - 3 months ago 12
HTML Question

Sending data to a table in loops

I have 3 for loops in my code, each loop will give one column data. I want to send 3 loops data into one table and each loop output should come in column not in row.

$displayname= $ABC| select DisplayName
$Name= $ABC| select Name
$State= $ABC| select State



$Outputreport = "<HTML><TITLE > Report </TITLE>
<BODY background-color:white;>
<body style=background-color:White;>
<font size=5;color =#f20e2d face=""Microsoft Tai le"">
<P> </P>
<Table style= width:50% align=center border=1 cellpadding=0
cellspacing=0 >
<TR bgcolor=gray align=center>
<TD><B>displayname- </B></TD>
<TD><B>Name- </B></TD>
<TD><B>State- </B></TD> </TR>"


Foreach($Entry in $displayname)
{ $Outputreport += "<TR><TD align=center>$($Entry.Name)</TD></TR>"
}
Foreach($Entry in $Name)
{ $Outputreport += "<TR><TD align=center>$($Entry.Name)</TD></TR>"
}
Foreach($Entry in $State)
{ $Outputreport += "<TR><TD align=center>$($Entry.Name)</TD></TR>"
}

Answer

That's not how HTML tables work. To get three columns, you need 3 <td> elements per </tr> row - you only really need one loop:

foreach($Entry in $ABC){
    $Outputreport += "<TR><TD align=center>$($Entry.DisplayName)</TD><TD align=center>$($Entry.Name)</TD><TD align=center>$($Entry.State)</TD></TR>"
}
Comments