I would first like to thank everyone for the space and the wealth of information I have already gained from lurking here.
I am having apretty major problem with a PHP MySQL project. (The problem is with the code, I think)
My code first queries the table that has the training criteria names. This is the colum headings. Then the code queries the table that contains the training records. Then it should output the data with each employee in its own unique row aligning the expiration date with the correct training criteria column. I was unable to get it to work properly, so as you can see in the attached code I print a row for each certification, instead of each employee.
function TableGenerator($emp_name, $timestamp, $cert_name, $emp_id)
{
$conditionalbgcolor=0;
$conditionaltextcolor=0;
//format the cell BG color based on the time before the certification will expire
if((time() >= ($timestamp-2592000)) &&(time() <= ($timestamp-604800)))
{
$conditionalbgcolor="#FFFF00";
$conditionaltextcolor="#000000";
}
elseif(time() >= ($timestamp-604800))
{
$conditionalbgcolor="#FF0000";
$conditionaltextcolor="#000000";
}
else
{
$conditionalbgcolor="#999999";
$conditionaltextcolor="#0000cc";
}
//need to add forms so that if the user clicks on the user's name they can see alll their certs as well as go into edit their info
//need to add form so that if the user clicks on a training name they can go into the training and edit its info
print '<tr><td align="center" bgcolor="'.$conditionalbgcolor.'"><font color="'.$conditionaltextcolor.'">
<form action="view_training_by_name.php" method="POST">
<input name="name" type="hidden" value="'.$_POST["name"].'">
<input name="ual" type="hidden" value="'.$_POST["ual"].'">
<input name="emp_id" type="hidden"value="'.$_POST["emp_id"].'">
<input name="loggedin" type="hidden" value="true">
<input name="requested_emp_id" type="hidden" value="'.$emp_id.'">
<input name="requested_emp_name" type="hidden" value="'.$emp_name.'">
<input type="submit" class="submitLink" value="'.$emp_name.'">
</form>
</font></td><td align="center" bgcolor="'.$conditionalbgcolor.'"><font color="'.$conditionaltextcolor.'">
<form action="view_training_by_cert.php" method="POST">
<input name="name" type="hidden" value="'.$_POST["name"].'">
<input name="ual" type="hidden" value="'.$_POST["ual"].'">
<input name="emp_id" type="hidden"value="'.$_POST["emp_id"].'">
<input name="loggedin" type="hidden" value="true">
<input name="requested_cert" type="hidden" value="'.$cert_name.'">
<input type="submit" class="submitLink" value="'.$cert_name.'">
</form>
</font></td><td align="center" bgcolor="'.$conditionalbgcolor.'"><font color="'.$conditionaltextcolor.'">'.date("n-j-y",$timestamp).'</font></td></tr>';
}
if(!IsSet($_POST["loggedin"]) || ($_POST["loggedin"]!="true"))
{
print'<font size="+1"><strong>You do not have access to this resource</strong></font>';
}
else
{
include("dbconnect.php");
$query="SELECT emp_certs.emp_ssn, emp_certs.cert_name, emp_certs.cert_expires, unix_timestamp(emp_certs.cert_expires), emp_table.emp_lname, emp_table.emp_fname, emp_table.emp_mi
FROM emp_certs, emp_table
WHERE emp_table.emp_SSN = emp_certs.emp_SSN and emp_table.emp_status='1' and emp_certs.emp_cert_status='1' order by unix_timestamp(emp_certs.cert_expires), emp_certs.cert_name, emp_table.emp_lname, emp_table.emp_fname";
$result=mysql_query($query) or die();
$numresults=mysql_num_rows($result);
//print out a heading for the table
print '<table width="75%" align="center">
<tr><td colspan="3" align="center" bgcolor="#0000cc"><font size="+1" color="#999999">Training records for all active employees</font></tr>';
print '<tr><td align="center" bgcolor="#0000cc"><font size="+1" color="#999999">Employee Name</td><td align="center" bgcolor="#0000cc"><font size="+1" color="#999999">Training Name</td><td align="center" bgcolor="#0000cc"><font size="+1" color="#999999">Training Expiration Date</td></tr>';
//loop through the results
while($myrow=mysql_fetch_array($result))
{
$emp_name=$myrow["emp_lname"].', '.$myrow["emp_fname"].' '.$myrow["emp_mi"];
TableGenerator($emp_name,$myrow["unix_timestamp(emp_certs.cert_expires)"],$myrow["cert_name"], $myrow["emp_ssn"]);
};
print '</table><br>
<br>';
print 'MySQL returned '.$numresults.' employee certifications';
}
Thanks in advance for any help anyone may be able to provide.