Hello All,
I am trying to display results of a query that creates a separate html table for each entry with a specific field value with the specified field value as the html table heading. For example.. Each html table would have a heading of the office field (say Paris Office ..and the servers displayed would belong to the Paris OFfice. The next table would have the heading Milan Office with all servers in that table belonging to the milan office and so on.
I have the SQL statement correct with order by office. However I can not get my head around how to create a table for each office grouping? Should i do the for each syntax? At the moment i am using the while loop. Which displays all servers in one bigtabble . Below is my code any help/hints/ tips would be great ! thanks!!!
<?php
if(!isset($mainfile)) { include("mainfile.php"); }
include ("magops_info.php");
$index = 0;
global $cookie, $user;
$user = base64_decode($user);
$cookie = explode(":", $user);
$username = $cookie[1];
$today = date("j/n/Y");
$sql="SELECT * FROM servers LEFT JOIN sites ON servers.site_ID=sites.site_ID LEFT JOIN server_types ON servers.server_type=server_types.type_ID inner join mag_op on mag_op.mag_ID = sites.primary_contact where user_name = '$username' ORDER BY site";
$mysql_result=mysql_query($sql,$connection);
$num_rows=mysql_num_rows($mysql_result);
if ( $num_rows == 0 ) {
echo "Sorry there is no information";
} else {
we have results
create table
echo "<TABLE ALIGN=\"CENTER\" BORDER=\"1\">";
echo "<TR><TH>name</TH><TH>IP</TH><TH>site</TH><TH>server_type</TH></TR>";
while ($row=mysql_fetch_array($mysql_result))
{
$name=$row["ser_name"];
$ip=$row["ip"];
$site=$row["site_ID"];
$s_name=$row["site"];
$type_ID=$row["server_type"];
$server_type=$row["type_name"];
$ID=$row["server_ID"];
echo "<TR><TD><A HREF=\"ser_change.php?row_id=$ID\">$name</A></TD><TD>$ip</TD><TD>$s_name</TD><TD>$server_type</TD></TR>";
}
} # end else
mysql_close($connection);
?>