Hi,
I've implemented the changes you suggest. For some reason I'm not getting the results inserted into the table. The print_r shows that the data is in the array. The nested foreach doesn't seem to work. I'm posting my entire test script as I don't know where I made my mistakes.
Thanks,
Noah Count
<?php
fieldtech();
function fieldtech () {
// connect to db
$server = "localhost:3306";
$username = "root";
$passwd = "p01f1ck";
$connect = mysql_connect($server, $username, $passwd);
if (!$connect)
{
die('Could not connect: ' . mysql_error());
}
//Fetch the results
mysql_select_db("Dispatch_Web", $connect)or die ('Error while connecting to database: ' . mysql_error());
$sql = "SELECT Assign, Ft_location, Tech FROM Fieldtech WHERE Ft_Date = CurDate() ORDER by Assign, Ft_location, Tech";
$result = mysql_query($sql);
if (!$result)
{
echo ("<p>CONNECTION ERROR:" . mysql_error() . "</p>");
}
$col=array("TTC","OTC","OVID","N");
$t_row=array("TROUBLE", "ORDERS");
$var=array();
while ($row = mysql_fetch_assoc($result))
{
$assign=$row['Assign'];
$location=$row['Ft_location'];
$var[$assign][$location][]=$row['Tech']; // fill the $var arrary
}
//Print the headers
print "<table border=\"1\" width=\"80%\">"; // change
print "<tr>";
print "<th> </th>";
foreach( $col AS $c )
{
print "<th width=\"25%\">$c</th>";
}
print "</tr>";
//Print the results
foreach( $t_row AS $r )
{
print "<tr><td>$r</td>";
foreach( $col AS $c )
{
if ( !empty( $var[$c][$r] ) )
printf( "<td>%s</td>" , implode( "<br />" , $var[$c][$r] ) );
else
print "<td> </td>";
}
print "</tr>";
}
// end the table
print "</table>";
// data test
print "<pre>";
print_r($var);
print "</pre>";
}
?>